﻿using Module_Debug.Hardware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using VT_Tool_DLL;

namespace Module_Debug
{
    public partial class VTDR7120 : Form
    {
        //---------------------R66455 the dll function define-----------------------------------
        //De_Mura
        //byte[] Erase_Flash_SyR66455_601_SSD =
        //{
        //    0x0d,0x01,0x40,0xc0,0x01,0x00,0xb7,0x07,0x42,0xb1,
        //    0x01,0x01,0xb2,0x05,0x1b,0xb3,0x44,0x59,0xb4,0x04,
        //    0x38,0xb5,0x08,0x70,0xb6,0x00,0x37,0xde,0x00,0x03,
        //    0xb9,0x00,0x00,0xba,0xc2,0x50,0xbb,0x00,0x0c,0xd6,
        //    0x00,0x05,0xb9,0x00,0x01,0xb8,0x00,0x00,0xc9,0x1b,
        //    0x09,0xca,0x3a,0x0c,0xcb,0x03,0x1b,0xcc,0x0f,0x14,
        //    0xdf,0x00,0x3d,0xb7,0x07,0x4b,0xff,0x98,0x21
        //};

        //byte[] SyR66455_621_DeMura_ON_Part_0 =
        //{
        //    0x30,0x01,0x02,0xb0,0x80,0x8a,0xb3
        //};

        //byte[] SyR66455_621_DeMura_ON_Part_1 =
        //{
        //    0x30,0x01,0x3c,0xd4,0x93,0x90,0x40,0x1e,0xe1,0x04,
        //    0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
        //    0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
        //    0x00,0x04,0x00,0x0f,0xff,0x00,0x00,0x0f,0xff,0x00,
        //    0x00,0x0f,0xff,0x00,0x00,0x03,0x20,0x00,0xdf,0x00,
        //    0xc8,0x01,0x00,0x4d,0x8b,0x00,0x4d,0x8b,0x00,0x4d,
        //    0x8b,0x03,0x38,0xea,0x03
        //};

        //        byte[] SyR66455_621_DeMura_OFF_Part_0 =
        //{
        //            0x30,0x01,0x02,0xb0,0x80,0x8a,0xb3
        //        };

        //byte[] SyR66455_621_DeMura_OFF_Part_1 =
        //{
        //    0x30,0x01,0x3c,0xd4,0x90,0x90,0x40,0x1e,0xe1,0x04,
        //    0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
        //    0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
        //    0x00,0x04,0x00,0x0f,0xff,0x00,0x00,0x0f,0xff,0x00,
        //    0x00,0x0f,0xff,0x00,0x00,0x03,0x20,0x00,0xdf,0x00,
        //    0xc8,0x01,0x00,0x4d,0x8b,0x00,0x4d,0x8b,0x00,0x4d,
        //    0x8b,0x03,0x38,0x15,0xc0
        //};

        //byte[] SyR66455_Read_DeMura_Flash_ID_0 =
        //{
        //    0x0d,0x02,0x48,0x02,0xb0,0x00,0x33,0xdf,0x00,0x00,
        //    0x58,0x83,0x2d,0x05,0x35,0x15,0x01,0x31,0x11,0x0b,
        //    0x50,0x00,0x02,0x00,0x00,0x43,0x84,0x00,0x10,0x00,
        //    0xdf,0xd4,0x0e,0x00,0x00,0x13,0xff,0x8c,0x27,0x17,
        //    0x0f,0x00,0x55,0x18,0x0f,0x00,0x1a,0x0f,0x00,0x1c,
        //    0x0f,0x00,0x1e,0x0f,0x00,0x00,0x00,0x00,0x06,0xf3,
        //    0x9f,0x00,0x00,0x00,0x02,0x02,0xf2,0x09,0x02,0x37,
        //    0x03,0x02,0x14,0xf4,0xff,0xd6,0xbe
        //};

        //byte[] SyR66455_Read_DeMura_Flash_ID_1 =
        //{
        //    0x30,0x02,0x04,0xf4,0x00,0x00,0x00,0xff,0xb9
        //};

        //byte[] SyR66455_Read_DeMura_Flash_ID_2 =
        //{
        //    0x0d,0x03,0x03,0xb7,0x07,0x4b,0x2e,0x0a
        //};
        //byte[] SyR66455_Read_DeMura_Flash_ID_3 =
        //{
        //    0x0a,0x07,0x15,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
        //    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        //    0x00,0x00,0x00,0xd5,0x70
        //};
        //byte[] SyR66455_Read_DeMura_Flash_ID_4 =
        //{
        //    0x0d,0x04,0x02,0x14,0xf4,0xf4,0xcb
        //};

        //        byte[] Test1 =
        //        {
        //            0x30,0x01,0x02,0xb0,0x00,0x1b,0x3b
        //        };
        //        byte[] Test2 =
        //        {
        //            0x30,0x01,0x33,0xdf,0x00,0x00,0x58,0x83,0x2d,0x05,
        //            0x35,0x15,0x01,0x31,0x11,0x0b,0x50,0x00,0x02,0x00,
        //            0x00,0x43,0x84,0x00,0x10,0x00,0xdf,0xd4,0x0e,0x00,
        //            0x00,0x13,0xff,0x8c,0x27,0x17,0x0f,0x00,0x55,0x18,
        //            0x0f,0x00,0x1a,0x0f,0x00,0x1c,0x0f,0x00,0x1e,0x0f,
        //            0x00,0x00,0x00,0x00,0x82,0xec
        //        };
        //        byte[] Test3 =
        //        {
        //            0x30,0x01,0x06,0xf3,0x9f,0x00,0x00,0x00,0x02,0x36,
        //            0xeb
        //        };
        //        byte[] Test4 =
        //        {
        //            0x30,0x01,0x02,0xf2,0x09,0xe1,0xbc
        //        };
        //        byte[] Test5 =
        //        {
        //            0x30,0x01,0x02,0x37,0x03,0xa9,0x57
        //        };
        //        byte[] Test6 =
        //        {
        //            0x30,0x01,0x02,0x14,0xf4,0x65,0x1a
        //        };
        //        byte[] Test7 =
        //        {
        //            0x30,0x02,0x04,0xf4,0x00,0x00,0x00,0xff,0xb9
        //        };

        //        byte[] SyR66455_Read_DeMura_CheckSum_0 =
        //{
        //            0x30,0x01,0x02,0xb0,0x00,0x1b,0x3b
        //        };
        //        byte[] SyR66455_Read_DeMura_CheckSum_1 =
        //        {
        //            0x30,0x01,0x01,0x0b,0x1d,0x43
        //        };
        //        byte[] SyR66455_Read_DeMura_CheckSum_2 =
        //        {
        //            0x30,0x02,0x04,0xe7,0x00,0x00,0x00,0x7f,0xc2
        //        };




        //        byte[] Erase_Flash_SyR66455_601_MIPI =
        //        {
        //            0x0d,0x12,0x1c,0x02,0xb0,0x00,0x33,0xdf,0x00,0x40,
        //            0x58,0x83,0x2d,0x05,0x35,0x15,0x01,0x31,0x11,0x6b,
        //            0x50,0x00,0x02,0x00,0x00,0x43,0x84,0x00,0x10,0x00,
        //            0xdf,0xd4,0x0e,0x00,0x00,0x13,0xff,0x8c,0x27,0x17,
        //            0x0f,0x00,0x55,0x18,0x0f,0x00,0x1a,0x0f,0x00,0x1c,
        //            0x0f,0x00,0x1e,0x0f,0x00,0x00,0x00,0x00,0x02,0xb0,
        //            0x00,0x06,0xf3,0x06,0x00,0x00,0x00,0x00,0x04,0xff,
        //            0xff,0xff,0x0a,0x02,0xf2,0x11,0x02,0xb0,0x00,0x06,
        //            0xf3,0x05,0x00,0x00,0x00,0x00,0x04,0xff,0xff,0xff,
        //            0x0a,0x02,0xf2,0x09,0x02,0xb0,0x00,0x02,0x37,0x02,
        //            0x04,0xff,0xff,0xff,0x0a,0x02,0x14,0xf4,0x04,0xff,
        //            0xff,0xff,0x0a,0x02,0xb0,0x00,0x06,0xf3,0x60,0x00,
        //            0x00,0x00,0x00,0x04,0xff,0xff,0xff,0x0a,0x02,0xf2,
        //            0x11,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
        //            0xfa,0x04,0xff,0xff,0xff,0xfa,0xff,0x2b,0xf0,0x00,
        //            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        //            0x00,0x00,0x00,0x00,0x00,0x00,0x00
        //        };
        //        byte[] Erase_Flash_SyR66455_601_MIPI_1 =
        //        {
        //            0x0d,0x02,0x58,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
        //            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
        //            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
        //            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
        //            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
        //            0xff,0xff,0xfa,0x02,0xb0,0x00,0x06,0xf3,0x05,0x00,
        //            0x00,0x00,0x00,0x04,0xff,0xff,0xff,0x0a,0x02,0xf2,
        //            0x09,0x02,0xb0,0x04,0x02,0x37,0x02,0x04,0xff,0xff,
        //            0xff,0x0a,0x02,0x14,0xf4,0x04,0xff,0xff,0xff,0x0a,
        //            0xff,0x07,0x3e
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_Init =//初始化部分
        //        {
        //            0x30,0x0f,0x02,0xb0,0x00,0xB9,0x61
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_0 =//初始化部分
        //        {
        //            0x30,0x01,0x02,0xb0,0x00,0x1b,0x3b
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_1 =//初始化部分
        //        {
        //            0x30,0x01,0x33,0xdf,0x00,0x40,0x58,0x83,0x2d,0x05,
        //            0x35,0x15,0x01,0x31,0x11,0x6b,0x50,0x00,0x02,0x00,
        //            0x00,0x43,0x84,0x00,0x10,0x00,0xdf,0xd4,0x0e,0x00,
        //            0x00,0x13,0xff,0x8c,0x27,0x17,0x0f,0x00,0x55,0x18,
        //            0x0f,0x00,0x1a,0x0f,0x00,0x1c,0x0f,0x00,0x1e,0x0f,
        //            0x00,0x00,0x00,0x00,0xa0,0x0c
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_2 =//循环部分
        //        {
        //            0x30,0x01,0x02,0xb0,0x04,0x5b,0xbf
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_3 =//循环部分
        //        {
        //            0x30,0x01,0x06,0xf3,0x06,0x00,0x00,0x00,0x00,0x98,
        //            0x5f
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_4 =//循环部分
        //        {
        //            0x30,0x01,0x02,0xf2,0x11,0x72,0x85
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_5 =//循环部分_变化_数据地址
        //        {
        //            0x30,0x01,0x06,0xf3,0x02,0x00,0x0f,0x00,0x7f,0xb2,
        //            0x10
        //        };
        //        byte[] SyR66455_601_Send_DeMura_Data_MIPI_6 =//循环部分_数据结尾
        //{
        //            0x30,0x01,0x02,0xf2,0x1b,0xd3,0xcf
        //        };


        //De_Mura
        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke  
        //==============ca310===============
        CaSDK Ca310Obj = new CaSDK();
        private double auto_lum;//
        private double auto_x;
        private double auto_y;
        private double auto_T;
        private double auto_duv;
        private bool ca310calFlag = false;
        private int[] tmp_gamma_195 = new int[93];
        private int[] tmp_gamma_160 = new int[33];
        private int[] tmp_gamma_162 = new int[75];
        private int[] tmp_gamma_120 = new int[78];
        private int[] tmp_gamma_010 = new int[75];
        private int[] tmp_gamma_350 = new int[75];
        private int[] tmp_gamma_300 = new int[75];


        /// <summary>
        /// /auto gamma add 20181031
        /// </summary>
        private int flag1 = 1;
        private int flag2 = 1;
        private int flag3 = 1;
        private Boolean flag_R = true;
        private Boolean flag_G = true;
        private Boolean flag_B = true;

        //private ushort[] gamma_r = new ushort[31];
        //private ushort[] gamma_g = new ushort[31];
        //private ushort[] gamma_b = new ushort[31];

        private ushort[] mygamma_r = new ushort[28];
        private ushort[] mygamma_g = new ushort[28];
        private ushort[] mygamma_b = new ushort[28];
        private int step_h = 10;
        private int step_l = 1;
        //==============ca310===============
        private int CAS200_Measure_Gray = 255;
        private int CAS200_Measure_Count = 0;
        private int CA200_Measure_CE = 0;
        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过   
                                                         // private byte[] Rec_tmp = new byte[1];//
        private byte[] Rec_tmp = new byte[5];//
        private byte[] Rec_tmp1 = new byte[1];//
        private byte[] Send_buf = new byte[1];
        private byte signal_mode;
        public byte start_trans_flag = 0;
        public byte continueflag = 0;

        public byte VTDR7120_0XFE_XX = 0;
        public byte Seil_port_Find_flag = 0;
        private byte[] Driver_IC = new byte[1];
        private List<string> ImageType;
        private delegate void MonitorSerialPortChangeEventHandler();
        private MonitorSerialPortChangeEventHandler MonitorCom;
        private int serialPortStatus;

        CRC16 CRCData = new CRC16();

        int frm_new_vtdr6110 = 0;
        //public frmStm32updata1(frmMain Frm)
        //{
        //    MainForm = Frm;
        //    InitializeComponent();
        //}
        private static bool Delay(int delayTime)
        {
            DateTime now = DateTime.Now;
            int s;
            do
            {
                TimeSpan spand = DateTime.Now - now;
                s = spand.Seconds;
                Application.DoEvents();
            }
            while (s < delayTime);
            return true;
        }
        frmMain MainForm = null;
        public VTDR7120(frmMain Frm)
        {
            MainForm = Frm;
            InitializeComponent();
            //MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
            string[] s = { ".bmp" };
            this.ImageType = new List<string>(s);
        }
        private void Frm_Activated(object sender, EventArgs e)
        {

        }
        //是否已经绑定了事件        
        private bool IsBindEvent(Type type, Control con, string eventName)
        {
            bool isBind = false;

            PropertyInfo pi = type.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);   //获取type类定义的所有事件的信息
            EventHandlerList ehl = (EventHandlerList)pi.GetValue(con, null);    //获取con对象的事件处理程序列表
            FieldInfo fieldInfo = (typeof(Control)).GetField("EventText", BindingFlags.Static | BindingFlags.NonPublic); //获取Control类Click事件的字段信息
            Delegate d = ehl[fieldInfo.GetValue(null)];
            if (d == null)
            {
                return isBind;
            }
            foreach (Delegate del in d.GetInvocationList())
            {
                if (del.Method.Name == eventName)
                {
                    isBind = true;
                    break;
                }
            }
            return isBind;
        }
        private void asdftest_dfa(object sender, EventArgs e)
        {
            // bool isBind = IsBindEvent(MainForm.comPort.GetType(), MainForm.comPort, "comboBox_TextChanged");
            //为Button1绑定一个事件处理程序
            Button btn = new Button();
            btn.Click += new
            EventHandler(Frm_Activated);
            //获取Button类定义的所有事件的信息
            PropertyInfo pi =
            (typeof(Button)).GetProperty("Events", BindingFlags.Instance |
            BindingFlags.NonPublic);



        }
        //{
        //    if (!isBind)

        //    {
        //         MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
        //    }
        //}
        //=================================Timer====Start=========================
        private void T1_Tick(object sender, EventArgs e)
        {
            T1.Enabled = false;
            //textBox1.Text = textBox1.Text + "通讯故障!\r\n";
            textBox1.Focus();//获取焦点
            textBox1.Select(textBox1.TextLength, 0);//光标定位到文本最后
            textBox1.ScrollToCaret();//滚动到光标处
        }
        private void T2_Tick(object sender, EventArgs e)
        {

            toolStripStatusLabel2.Text = DateTime.Now.ToString();

        }
        //=================================Timer====end=========================
        private void SerialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            //if (MainForm.IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = MainForm.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                MainForm.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    if (buffer[0] == 0x0B)          //返回 STM32内部 flash 的配置文件数据
                    {
                        if (buffer.Count >= (Int16)(buffer[2] << 8) + (buffer[3]) + 7)
                        {
                            Rec_tmp = new byte[(Int16)(buffer[2] << 8) + (buffer[3]) + 7];
                            byte[] crcTemp = new byte[(Int16)(buffer[2] << 8) + (buffer[3]) + 7];
                            buffer.CopyTo(0, crcTemp, 0, (Int16)(buffer[2] << 8) + (buffer[3]) + 7);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[(Int16)(buffer[2] << 8) + (buffer[3]) + 7 - 2] != CRCH && buffer[(Int16)(buffer[2] << 8) + (buffer[3]) + 7 - 1] != CRCL) //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, (Int16)(buffer[2] << 8) + (buffer[3]) + 7);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, (Int16)(buffer[2] << 8) + (buffer[3]) + 7);//正确分析一条数据，从缓存中移除数据。
                            }

                        }
                    }
                    else if (buffer[0] == 0xFE)
                    {
                        Rec_tmp = new byte[buffer[2] + 5];
                        byte[] crcTemp = new byte[buffer[2] + 5];
                        buffer.CopyTo(0, crcTemp, 0, buffer[2] + 5);

                        CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                        if (buffer[buffer[2] + 5 - 2] != CRCH && buffer[buffer[2] + 5 - 1] != CRCL)     //CRC校验出错
                        {
                            buffer.RemoveRange(0, buffer.Count);
                        }
                        else
                        {
                            buffer.CopyTo(0, Rec_tmp, 0, buffer[2] + 5);//复制一条完整数据到具体的数据缓存   
                            data_1_catched = true;
                            buffer.RemoveRange(0, buffer[2] + 5);//正确分析一条数据，从缓存中移除数据。
                            if (Rec_tmp[4] == 0)
                                continueflag = 1;
                        }
                    }
                    else if (buffer[0] == 0x55)     //STM32 更新bin文件成功  返回
                    {
                        if (buffer.Count >= (buffer[2] + 5))
                        {
                            Rec_tmp = new byte[(buffer[2] + 5)];
                            byte[] crcTemp = new byte[(buffer[2] + 5)];
                            buffer.CopyTo(0, crcTemp, 0, (buffer[2] + 5));

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[(buffer[2] + 5) - 2] != CRCH && buffer[(buffer[2] + 5) - 1] != CRCL)       //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, (buffer[2] + 5));//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, (buffer[2] + 5));//正确分析一条数据，从缓存中移除数据。
                                switch (Rec_tmp[3])
                                {
                                    case 0x00:
                                        {
                                            start_trans_flag = 1;
                                        }
                                        break;
                                    case 0x01:
                                        {
                                            if (MainForm.comPort.IsOpen == true) MainForm.comPort.Close();
                                        }
                                        break;
                                    case 0x02:
                                        {
                                            start_trans_flag = 0;
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }

                        }
                    }
                    //RECEIVE
                    // 0x0A: 模组Timing参数 设置  返回
                    // 0x0D: 模组的SSD2828配置数据、DriverIC初始化数据  设置  返回
                    // 0x08: RM67120的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x09: RM67195的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x19: RM67295的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x29: RM67198的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2E: RM67198的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x0E: RM67160的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x1E: RM67162的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2A: NT37710的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2b: HX37710的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2C: RM69300的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2D: ICN9608的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x30: R66455 的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x31: TC1100 的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2F: Demura操作    设置  返回
                    // 0x3C: RM69350的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x4A: CH13721的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x4C: UD61720的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x4D: VTDR6110的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x60: VTDR7120的Gamma读写、寄存器读写、OTP读写    设置  返回
                    else if (((buffer[0] == 0x1E) || (buffer[0] == 0x0E) || (buffer[0] == 0x0D) || (buffer[0] == 0x0A) || (buffer[0] == 0x09) || (buffer[0] == 0x08) || (buffer[0] == 0x19) || (buffer[0] == 0x29) || (buffer[0] == 0x2A) || (buffer[0] == 0x09) || (buffer[0] == 0x2E) || (buffer[0] == 0x2B) || (buffer[0] == 0x2C) || (buffer[0] == 0x2D) || (buffer[0] == 0x2F) || (buffer[0] == 0x30) || (buffer[0] == 0x31) || (buffer[0] == 0x3C) || (buffer[0] == 0x3D) || (buffer[0] == 0x4A) || (buffer[0] == 0x4C) || (buffer[0] == 0x4D) || (buffer[0] == 0x60)) && (Setting.TempRecord.cmdLen > 0))
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }
                        }
                    }
                    else
                        buffer.RemoveRange(0, buffer.Count);
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        T1.Enabled = false; //停止超时计数

                        //------------------------------------------------------------------------------------------------------------------------
                        if ((Rec_tmp[0] == 0x09) || (Rec_tmp[0] == 0x19) || (Rec_tmp[0] == 0x29) || (Rec_tmp[0] == 0x2e))  //RM67195 & RM67295 & RM67198&RM69298
                        {
                            ;
                        }

                        //返回接受到的返回值设定并返回相应文本
                        else if (Rec_tmp[0] == 0x60)      //VTDR7120
                        {
                            string tmp = "";
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            textBox1.Text = textBox1.Text + "写寄存器\tOK！\r\n";
                                    }
                                    break;
                                case 0x02:
                                    {
                                        //if (Setting.TempRecord.VTDR7120CmdType == 0x02)  //register read
                                        {
                                            //string tmp = "";
                                            for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                            {
                                                tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                            }
                                            tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                            VTDR7120_txtRegData.Text = tmp;
                                            textBox1.Text = textBox1.Text + "寄存器\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x08:
                                    {
                                        if (T18.Enabled == true)
                                        {

                                        }
                                        else
                                        {
                                            if (Rec_tmp[4] == 0x00)
                                                textBox1.Text = textBox1.Text + "GAMMA \t写 OK！\r\n";
                                            else if (Rec_tmp[4] == 0x02)
                                                textBox1.Text = textBox1.Text + "GAMMA \t写 ERROR！\r\n";
                                        }



                                    }
                                    break;
                                case 0x07:
                                    {
                                    }
                                    break;
                                case 0x09:
                                    {
                                        if (Setting.TempRecord.VTDR7120CmdType == 0x03)
                                        {
                                            VTDR7120_R0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VTDR7120_R1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VTDR7120_R3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VTDR7120_R5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VTDR7120_R7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VTDR7120_R11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VTDR7120_R15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VTDR7120_R19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VTDR7120_R23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VTDR7120_R27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VTDR7120_R31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VTDR7120_R35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VTDR7120_R39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VTDR7120_R47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VTDR7120_R55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VTDR7120_R63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VTDR7120_R71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VTDR7120_R79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VTDR7120_R95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VTDR7120_R111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VTDR7120_R127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VTDR7120_R159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VTDR7120_R191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VTDR7120_R223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VTDR7120_R255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());

                                            textBox1.Text = textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }

                                        else if (Setting.TempRecord.VTDR7120CmdType == 0x04)
                                        {
                                            VTDR7120_G0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VTDR7120_G1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VTDR7120_G3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VTDR7120_G5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VTDR7120_G7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VTDR7120_G11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VTDR7120_G15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VTDR7120_G19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VTDR7120_G23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VTDR7120_G27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VTDR7120_G31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VTDR7120_G35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VTDR7120_G39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VTDR7120_G47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VTDR7120_G55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VTDR7120_G63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VTDR7120_G71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VTDR7120_G79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VTDR7120_G95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VTDR7120_G111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VTDR7120_G127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VTDR7120_G159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VTDR7120_G191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VTDR7120_G223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VTDR7120_G255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            textBox1.Text = textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";
                                        }

                                        else if (Setting.TempRecord.VTDR7120CmdType == 0x05)
                                        {
                                            VTDR7120_B0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VTDR7120_B1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VTDR7120_B3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VTDR7120_B5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VTDR7120_B7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VTDR7120_B11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VTDR7120_B15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VTDR7120_B19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VTDR7120_B23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VTDR7120_B27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VTDR7120_B31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VTDR7120_B35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VTDR7120_B39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VTDR7120_B47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VTDR7120_B55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VTDR7120_B63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VTDR7120_B71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VTDR7120_B79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VTDR7120_B95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VTDR7120_B111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VTDR7120_B127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VTDR7120_B159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VTDR7120_B191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VTDR7120_B223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VTDR7120_B255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());

                                            textBox1.Text = textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x11:
                                    {
                                        switch (Rec_tmp[3])
                                        {
                                            case 0x01:
                                            case 0x02:
                                            case 0x03:
                                                {
                                                    textBox1.Text = textBox1.Text + "Gamma切换成功！\r\n";
                                                }
                                                break;
                                            default: break;
                                        }
                                        /*if (Rec_tmp[4] == 0x00)
                                        {
                                            textBox1.Text = textBox1.Text + "Gamma切换成功！\r\n";
                                        }*/
                                    }
                                    break;
                                //page 3 返回
                                case 0x0D:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP Gamma \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP Gamma \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + "OTP  P3/Gamma OK！\r\n";
                                    }
                                    break;
                                //otp ALL返回
                                case 0x0E:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP ALL \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP ALL \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP ALL  OK！\r\n";
                                    }
                                    break;
                                //OTP Page 0
                                case 0x0F:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 0 \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 0 \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP Page 0  OK！\r\n";
                                    }
                                    break;
                                case 0x1A:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 4 \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 4 \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP Page 4  OK！\r\n";
                                    }
                                    break;
                                case 0x1B:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 1 \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 1 \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP Page 1  OK！\r\n";
                                    }
                                    break;
                                case 0x1C:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 2 \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 2 \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP Page2  OK！\r\n";
                                    }
                                    break;
                                case 0x1D:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 5 \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 5 \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP Page5  OK！\r\n";
                                    }
                                    break;
                                case 0x1E:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 7 \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "OTP Page 7 \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP Page7  OK！\r\n";
                                    }
                                    break;
                                case 0x1F:
                                    {
                                        //if (Rec_tmp[3] == 0x00)
                                        //    textBox1.Text = textBox1.Text + "Write 2810 \t写 OK！\r\n";
                                        //else if (Rec_tmp[3] == 0x02)
                                        //    textBox1.Text = textBox1.Text + "Write 2810 \t写 ERROR！\r\n";
                                        textBox1.Text = textBox1.Text + " OTP Page8  OK！\r\n";
                                    }
                                    break;
                                case 0x2A:
                                    {
                                        textBox1.Text = textBox1.Text + " OTP Page3 OK！\r\n";
                                    }
                                    break;
                                case 0x2B:
                                    {
                                        textBox1.Text = textBox1.Text + " OTP Page6  OK！\r\n";
                                    }
                                    break;
                                case 0x0A:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            textBox1.Text = textBox1.Text + "GAMMA \t传输 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            textBox1.Text = textBox1.Text + "GAMMA \t传输 ERROR！\r\n";
                                    }
                                    break;
                                //case 0x20:
                                //    {
                                //        //if (Setting.TempRecord.VTDR7120CmdType == 0x02)  //register read
                                //        {

                                //            for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                //            {
                                //                tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                //            }
                                //            tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                //            textBox1.Text = textBox1.Text + "\n flash ID \r\n" + tmp + "\n flash \t读 完成！\r\n";
                                //            //textBox1.Text = "\r\n flash ID\r\n" + textBox1.Text + "\r\n 寄存器\t读 OK！\r\n";
                                //        }
                                //    }
                                //    break;
                                case 0x20: //flash read
                                    {
                                        //textBox1.Text = textBox1.Text + "Flash read： " + Rec_tmp[3].ToString("x2") + "," + Rec_tmp[4].ToString("x2") + "\r\n";
                                        textBox1.Text = textBox1.Text + "Flash read:" + String.Format("{0:X2}", Rec_tmp[3]) + "," + String.Format("{0:X2}", Rec_tmp[4]) + "\r\n";
                                    }
                                    break;
                                //case 0x21:
                                //    textBox1.Text = textBox1.Text + "flash 擦除 完成！\r\n";
                                //    break;
                                case 0x21:
                                    {
                                        textBox1.Text = textBox1.Text + "Flash erase： " + Rec_tmp[3].ToString("x2") + "\r\n";
                                        textBox1.Text = textBox1.Text + "flash 擦除 完成！\r\n";
                                    }
                                    break;

                                case 0x22:
                                    if ((Rec_tmp[3] == 0x02) && (Rec_tmp[4] == 0x02))
                                    {
                                        textBox1.Text = textBox1.Text + "Flash_enable OK！\r\n";
                                    }
                                    else
                                    {
                                        textBox1.Text = textBox1.Text + "Flash_enable Fail！\r\n";
                                    }
                                    break;
                                case 0x23:
                                    //Setting.TempRecord.cmdLen = 13;////CRC 特殊处理
                                    for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                    {
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                    }
                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                    textBox1.Text = textBox1.Text + tmp + "\n ";
                                    textBox1.Text = textBox1.Text + "Check_Flash 完成！\r\n";
                                    break;
                                case 0x24:
                                    textBox1.Text = textBox1.Text + "\n Step_Five 完成！\r\n";
                                    break;
                                case 0x25:
                                    textBox1.Text = textBox1.Text + "Write_Flash 完成！\r\n";
                                    break;
                                case 0x26:
                                    //Setting.TempRecord.cmdLen = 15;////CRC 特殊处理
                                    for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                    {
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                    }
                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                    textBox1.Text = textBox1.Text + tmp + "\n ";
                                    textBox1.Text = textBox1.Text + "Check_Flash 完成！\r\n";
                                    break;
                                case 0x29:
                                    {
                                        if (Rec_tmp[4] == 0)
                                        { textBox1.Text = textBox1.Text + "Flash Program 1 完成" + "\r\n"; }
                                    }
                                    break;
                                case 0x30:
                                    {
                                        if (Rec_tmp[3] == 0x70)
                                        {
                                            textBox1.Text = textBox1.Text + "Flash Program 2： " + Rec_tmp[3].ToString("x") + "\r\n";
                                            textBox1.Text = textBox1.Text + "Flash Program 2完成！\r\n";
                                        }
                                    }
                                    break;
                                case 0x31:
                                    {
                                        textBox1.Text = textBox1.Text + "Reset_And_Reload EB： " + Rec_tmp[3].ToString("x") + "," + Rec_tmp[4].ToString("x") + "\r\n";
                                        textBox1.Text = textBox1.Text + "Reload 完成！\r\n";
                                    }
                                    break;
                                default: break;

                            }
                        }


                        ////---------------------------------------------------Demura----------------------------------------
                        else if (Rec_tmp[0] == 0x2F)  //Demura
                        {
                            if ((Rec_tmp[7] == 0x2E) || (Rec_tmp[7] == 0x3C))   // 297/298/299  //350
                            {
                                if (Rec_tmp[7] == 0x2E)// 297/298/299
                                {
                                    textBox1.Text = textBox1.Text + "297 298 299\r\n";
                                }
                                else if (Rec_tmp[7] == 0x3C) //350
                                {
                                    textBox1.Text = textBox1.Text + "350\r\n";
                                }
                                switch (Rec_tmp[1])
                                {
                                    case 0x01:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura RAM Enable\r\n";
                                        }
                                        break;
                                    case 0x02:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura RAM Disable\r\n";
                                        }
                                        break;
                                    case 0x03:
                                        {
                                            if (Rec_tmp[7] == 0x2E)// 297/298/299
                                            {
                                                if (Rec_tmp[4] == 0x80)
                                                {
                                                    textBox1.Text = textBox1.Text + "Demura RAM write Flash complete ! \r\n";
                                                }
                                            }
                                            else if (Rec_tmp[7] == 0x3C) ///350
                                            {
                                                if (Rec_tmp[4] == 0x08)
                                                {
                                                    textBox1.Text = textBox1.Text + "Demura RAM write Flash1 complete ! \r\n";
                                                }
                                                else if (Rec_tmp[4] == 0x00)
                                                {
                                                    textBox1.Text = textBox1.Text + "ERROR: write Flash1 timeout ! \r\n";
                                                }
                                            }
                                        }
                                        break;
                                    case 0x0A:///350 only
                                        {
                                            if (Rec_tmp[7] == 0x3C) ///350
                                            {
                                                if (Rec_tmp[4] == 0x08)
                                                {
                                                    textBox1.Text = textBox1.Text + "Demura RAM write Flash2 complete ! \r\n";
                                                    MessageBox.Show("载入完成！");
                                                }
                                                else if (Rec_tmp[4] == 0x00)
                                                {
                                                    textBox1.Text = textBox1.Text + "ERROR: write Flash2 timeout ! \r\n";
                                                }
                                            }
                                        }
                                        break;
                                    case 0x04:
                                        {
                                            textBox1.Text = textBox1.Text + "Checksum: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "\r\n";
                                        }
                                        break;
                                    case 0x05:
                                        {
                                            if (Rec_tmp[7] == 0x2E)// 297/298/299
                                            {
                                                if (Rec_tmp[4] == 0x80)
                                                {
                                                    textBox1.Text = textBox1.Text + "Flash Erase Success ! \r\n";
                                                }
                                            }
                                            else if (Rec_tmp[7] == 0x3C) ///350
                                            {
                                                if (Rec_tmp[4] == 0x08)
                                                {
                                                    textBox1.Text = textBox1.Text + "Flash Erase Success ! \r\n";
                                                }
                                            }
                                        }
                                        break;
                                    case 0x06:
                                        {
                                            textBox1.Text = textBox1.Text + "flash ID: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "," + Rec_tmp[6].ToString("x") + "\r\n";
                                        }
                                        break;
                                    case 0x07:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura function on \r\n";
                                        }
                                        break;
                                    case 0x08:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura function off \r\n";
                                        }
                                        break;
                                    case 0x09:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura OTP complete$ \r\n";
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }

                        textBox1.Focus();//获取焦点
                        textBox1.Select(textBox1.TextLength, 0);//光标定位到文本最后
                        textBox1.ScrollToCaret();//滚动到光标处
                        if (textBox1.Lines.Length > 200) textBox1.Text = "";
                    }));
                }
            }
            finally
            {
                Listening = false;

            }

        }
        //=================================LCD cfg function:OLED_Show_Click====Start=================
        private void OLED_Show_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[25];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 25;
            UInt32 ICS307Temp = 0x00;
            Send_buf[0] = 0x0A; //LCD配置标志
            Send_buf[2] = 0x15; //数据长度
            switch (btnTmp.Name)
            {

                case "btnPatternW":                             //写入Pattern参数
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = byte.Parse(numPatternR.Value.ToString());
                        Send_buf[4] = byte.Parse(numPatternG.Value.ToString());
                        Send_buf[5] = byte.Parse(numPatternB.Value.ToString());
                    }
                    break;
                //case "btnPatternR": Send_buf[1] = 0x08; break; //读取Pattern参数
                //case "btnReload": Send_buf[1] = 0x0A; break; //重新载入图片
                //case "btnPrevPic": Send_buf[1] = 0x0B; break; //上一张图片
                //case "btnNextPic": Send_buf[1] = 0x0C; break; //下一张图片
                //case "mtReadversion": Send_buf[1] = 0x0D; break; //读取程式版本
                case "btnred":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0xFF;
                        Send_buf[4] = 0;
                        Send_buf[5] = 0;
                    }
                    break; //R
                case "btngreen":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0;
                        Send_buf[4] = 0xFF;
                        Send_buf[5] = 0;
                    }
                    break; //G
                case "btnblue":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0;
                        Send_buf[4] = 0;
                        Send_buf[5] = 0xFF;
                    }
                    break; //B
                case "btnwhite":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0xFF;
                        Send_buf[4] = 0xFF;
                        Send_buf[5] = 0xFF;
                    }
                    break; //W
                case "btnblack":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0;
                        Send_buf[4] = 0;
                        Send_buf[5] = 0;
                    }
                    break; //BL
                case "btnPattern16":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 16;
                        Send_buf[4] = 16;
                        Send_buf[5] = 16;
                        numPatternR.Value = 16;
                        numPatternG.Value = 16;
                        numPatternB.Value = 16;
                    }
                    break; //16灰阶

                case "btnPattern32":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 32;
                        Send_buf[4] = 32;
                        Send_buf[5] = 32;
                        numPatternR.Value = 32;
                        numPatternG.Value = 32;
                        numPatternB.Value = 32;
                    }
                    break; //32灰阶

                case "btnPattern64":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 64;
                        Send_buf[4] = 64;
                        Send_buf[5] = 64;
                        numPatternR.Value = 64;
                        numPatternG.Value = 64;
                        numPatternB.Value = 64;
                    }
                    break; //64灰阶

                case "btnPattern96":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 96;
                        Send_buf[4] = 96;
                        Send_buf[5] = 96;
                        numPatternR.Value = 96;
                        numPatternG.Value = 96;
                        numPatternB.Value = 96;
                    }
                    break; //96灰阶

                case "btnPattern128":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 128;
                        Send_buf[4] = 128;
                        Send_buf[5] = 128;
                        numPatternR.Value = 128;
                        numPatternG.Value = 128;
                        numPatternB.Value = 128;
                    }
                    break; //128灰阶
                case "btnPattern192":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 192;
                        Send_buf[4] = 192;
                        Send_buf[5] = 192;
                        numPatternR.Value = 192;
                        numPatternG.Value = 192;
                        numPatternB.Value = 192;
                    }
                    break; //192灰阶

                case "btnPattern224":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 224;
                        Send_buf[4] = 224;
                        Send_buf[5] = 224;
                        numPatternR.Value = 224;
                        numPatternG.Value = 224;
                        numPatternB.Value = 224;
                    }
                    break; //224灰阶











                default:
                    break;
            }

            CRCData.CalculateCrc16(Send_buf, out Send_buf[23], out Send_buf[24]);
            try
            {
                MainForm.comPort.Write(Send_buf, 0, 25);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            Thread.Sleep(800);
        }
        private void numPatternR_ValueChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                numPatternG.Value = numPatternR.Value;
                numPatternB.Value = numPatternG.Value;
            }
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                numPatternG.Value = numPatternR.Value;
                numPatternB.Value = numPatternG.Value;
            }
        }
        private void CAS200_Measure_Information(double Dgv_lum, double Dgv_x, double Dgv_y)
        {
            int Row_Accum = 0, Current_Index = 0, Row_flag = 0;

            DataGridViewRow Row1 = new DataGridViewRow();
            Row_Accum = this.CAS200_dataGridView.Rows.Count - 1;
            if (Row_Accum != 0)
            {
                Current_Index = this.CAS200_dataGridView.SelectedCells[0].RowIndex;
                if ((Current_Index != Row_Accum - 1) && (Current_Index != Row_Accum))
                {
                    Row_Accum = Current_Index;
                    Row_flag = 1;
                }
                else
                {
                    this.CAS200_dataGridView.Rows.Add(Row1);
                }
                if ((Row_Accum != 0) && (Row_flag != 1))
                {
                    if (Current_Index != Row_Accum)
                    {
                        this.CAS200_dataGridView.Rows[Row_Accum - 1].Selected = false;
                        this.CAS200_dataGridView.Rows[Row_Accum].Selected = true;
                    }
                }
            }
            else
            {
                this.CAS200_dataGridView.Rows.Add(Row1);
            }
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[0].Value = Row_Accum + 1;//序号
            //Rows[x]为第x行,Cells[x]为第x列
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[1].Value = Dgv_x.ToString("#0.0000");
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[2].Value = Dgv_y.ToString("#0.0000");
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[3].Value = Dgv_lum.ToString("#0.0000");
            if (Row_flag == 1)
            {
                Row_flag = 0;
                Row_Accum = this.CAS200_dataGridView.Rows.Count - 1;
                this.CAS200_dataGridView.Rows[Current_Index].Selected = false;
                this.CAS200_dataGridView.Rows[Row_Accum - 1].Selected = true;
            }
            CAS200_dataGridView.FirstDisplayedScrollingRowIndex = CAS200_dataGridView.RowCount - 1;
        }
        private void Pattern_Write(byte R_value, byte G_value, byte B_value)
        {
            numPatternR.Value = R_value;
            numPatternG.Value = G_value;
            numPatternB.Value = B_value;
            OLED_Show_Click(btnPatternW, null);
        }
        bool lumdataReadyFlag;
        //private void T3_Tick(object sender, EventArgs e)
        //{
        //        Int32 step;
        //        step =1; 
        //        if (CAS200_Measure_Gray > 0)
        //        {
        //        VTDR7120_51Reg_trackBar.Value = CAS200_Measure_Gray - 1;
        //        }
        //        else
        //        {
        //        VTDR7120_51Reg_trackBar.Value = 0;
        //        }
        //        VTDR7120_txtRegData.Text = "51,00," + VTDR7120_51Reg_trackBar.Value.ToString("x2");
        //        VTDR7120_RegWR_Click(VTDR7120_51Reg_W, e);
        //        VTDR7120_label.Text = CAS200_Measure_Gray.ToString() + " 阶";
        //         CAS200_Measure_Gray -= step;

        //    if (CAS200_Measure_Gray < 0)
        //    {
        //        T3.Enabled = false;
        //    }
        //    else if (cbx_follow_gamma_points.Checked == true)  //follow gamma绑点
        //    {
        //        T3.Enabled = false;
        //        if (Vesa_Check.Checked == true)
        //        {
        //            if (Point_VTDR7120_tmp[0] == 255)
        //            {
        //                VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120_tmp[CAS200_Measure_Count] + ".dsc_0001.bmp");
        //            }
        //            else
        //            { VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120_tmp[CAS200_Measure_Count ] + ".dsc_0001.bmp"); }

        //            CAS200_Measure_Count++;
        //        }
        //        else
        //        {
        //            if (Point_VTDR7120[0] == 255)
        //            {
        //                numPatternB.Value = numPatternG.Value = numPatternR.Value = Point_VTDR7120[CAS200_Measure_Count];
        //            }
        //            else
        //            {
        //                //从第三笔数据开始
        //                numPatternB.Value = numPatternG.Value = numPatternR.Value = Point_VTDR7120[CAS200_Measure_Count + 2];
        //            }
        //            Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
        //        }
        //        //CAS200_Measure_Count++;
        //        if (CAS200_Measure_Count > 29)
        //        {
        //            T3.Enabled = false;
        //            textBox1.Text += "绑点数据量测完毕\r\n";
        //            lumdataReadyFlag = true;
        //        }
        //        else
        //        {
        //            T3.Enabled = true;
        //        }

        //    }
        //    else
        //    {
        //        if ((Convert.ToInt16(numPatternR.Value.ToString()) + Convert.ToInt16(numPatternB.Value.ToString()) + Convert.ToInt16(numPatternG.Value.ToString()) - int.Parse(CAS200_txt0.Text)) >= 0)
        //        {
        //            if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
        //            {
        //                if (numPatternR.Value != 0)
        //                {
        //                    numPatternR.Value = (byte)(Convert.ToInt16(numPatternR.Value.ToString()) - int.Parse(CAS200_txt0.Text));
        //                }
        //                if (numPatternG.Value != 0)
        //                {
        //                    numPatternG.Value = (byte)(Convert.ToInt16(numPatternG.Value.ToString()) - int.Parse(CAS200_txt0.Text));
        //                }
        //                if (numPatternB.Value != 0)
        //                {
        //                    numPatternB.Value = (byte)(Convert.ToInt16(numPatternB.Value.ToString()) - int.Parse(CAS200_txt0.Text));
        //                }
        //            }
        //            else
        //            {
        //                numPatternB.Value = numPatternG.Value = numPatternR.Value = (byte)(Convert.ToInt16(numPatternR.Value.ToString()) - int.Parse(CAS200_txt0.Text));
        //            }
        //            if (Vesa_Check.Checked == true)
        //            {
        //                //RM692Cx_btnPrevPic_Run("A" + numPatternB.Value + ".dsc_0001.bmp");
        //            }
        //            else
        //            {
        //                Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
        //            }
        //        }
        //        else
        //        {
        //            T3.Enabled = false;
        //        }
        //    }
        //    Thread.Sleep(50);
        //    btn_CAS200_Synt_Click(btn_CAS200_Measure, null); //量测
        //    CAS200_Measure_Count++;
        //    if ((cbx_follow_51_points.Checked == true) && (CAS200_Measure_Gray <= 0))//51调光时，如果调到最后一阶,则测量后再把51调回去
        //    {
        //        VTDR7120_51Reg_trackBar.Value = 255;
        //        VTDR7120_RegWR_Click(VTDR7120_51Reg_W, e);
        //        VTDR7120_label.Text = CAS200_Measure_Gray.ToString() + " 阶";
        //    }
        //}
        private void T3_Tick(object sender, EventArgs e)
        {

            if (Vesa_Check.Checked == true)
            {
                if (cbx_follow_gamma_points.Checked == true)  //选择了绑点
                {
                    //if (CAS200_Measure_Count > 24)
                    if (CAS200_Measure_Count > 23)
                    {
                        T3.Enabled = false;
                        textBox1.Text += "绑点数据量测完毕\r\n";
                        lumdataReadyFlag = true;
                    }
                    else
                    {
                        VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120_tmp[CAS200_Measure_Count] + ".dsc_0001.bmp");
                    }
                    CAS200_Measure_Count++;
                }
                Thread.Sleep(50);
                btn_CAS200_Synt_Click(btn_CAS200_Measure, null); //量测
            }


            if (rbt_OtherMeasure.Checked == true)//选择全灰阶
            {
                int gary = 0;

                if (CAS200_Measure_Count > 20)
                {
                    T3.Enabled = false;
                    textBox1.Text += "绑点数据量测完毕\r\n";
                    lumdataReadyFlag = true;
                }
                else
                {
                    VTDR7120_btnPrevPic_Run("A" + CAS200_Measure_Count + ".dsc_0001.bmp");
                }
                CAS200_Measure_Count++;

                Thread.Sleep(50);
                btn_CAS200_Synt_Click(btn_CAS200_Measure, null); //量测
            }

        }





        //设置T20的间隔
        private void T20_Tick_start()
        {
            T20.Interval = int.Parse("10");//延时
            T20.Enabled = true;
        }

        //T20一打开，执行一次测量，在再关闭
        private void T20_Tick(object sender, EventArgs e)
        {
            btn_CAS200_Synt_Click(btn_CAS200_Measure, null); //量测
            T20.Enabled = false;
        }



        int[] Point_VTDR7120_tmp = new int[25] { 255, 223, 191, 159, 127, 111, 95, 79, 71, 63, 55, 47, 39, 35, 31, 27, 23, 19, 15, 11, 7, 5, 3, 1, 0 };


        ////放在外面是为了暂停按键调用
        bool measure_all_gray_flag = true;
        bool measure_node_flag = true;
        int CAS200_Measure_Count_High2Low = 255;

        private void btn_CAS200_Synt_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;

            switch (btnTmp.Name)
            {
                case "btn_CAS200_Measure":
                    {
                        Msr_CA310();
                        CAS200_Measure_Information(auto_lum, auto_x, auto_y);
                    }
                    break;
                case "btn_CAS200Save":
                    {
                        SaveFileDialog sf = new SaveFileDialog(); //对话框
                        sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型

                        string str = "序号,x坐标,y坐标,亮度\r\n";
                        if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
                        {
                            if (sf.FileName == "") return; //如果没有输入文件名
                            try
                            {
                                StreamWriter sw = null; //文件流
                                sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                                for (int i = 0; i < (this.CAS200_dataGridView.Rows.Count - 1); i++)
                                {
                                    str = str + this.CAS200_dataGridView.Rows[i].Cells[0].Value.ToString() + ","
                                        + this.CAS200_dataGridView.Rows[i].Cells[1].Value.ToString() + ","
                                        + this.CAS200_dataGridView.Rows[i].Cells[2].Value.ToString() + ","
                                        + this.CAS200_dataGridView.Rows[i].Cells[3].Value.ToString() + "\r\n";

                                }
                                sw.WriteLine(str);
                                sw.Dispose(); //释放资源
                                sw.Close(); //关闭数据流
                                MessageBox.Show("CA310数据保存OK！", "系统提示：");
                            }
                            catch
                            {
                                MessageBox.Show("CA310数据保存时发生错误，请再试！", "系统提示：");
                            }
                        }
                    }
                    break;
                case "btn_CAS200_load":
                    {
                        OpenFileDialog sf = new OpenFileDialog();
                        int Line_Count = 0;
                        string strtmp = "";
                        sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义文件的类型
                        sf.Title = "数据导入";
                        if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
                        {
                            FileStream fs = new FileStream(sf.FileName, FileMode.Open, FileAccess.Read);
                            StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                            streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                            string strLine = streamReader.ReadLine();
                            while (!string.IsNullOrEmpty(strLine))
                            {
                                strtmp = strtmp + strLine + ",";
                                strLine = streamReader.ReadLine(); //循环读取下一行
                                Line_Count++;
                            }
                            fs.Close(); //关闭流
                            streamReader.Close();
                            string[] arrtmp = strtmp.Split(new Char[] { ',' });
                            for (int j = 1; j < Line_Count - 1; j++)
                            {
                                DataGridViewRow Row1 = new DataGridViewRow();
                                CAS200_dataGridView.Rows.Add(Row1);
                            }
                            try
                            {
                                for (int i = 0; i < Line_Count - 1; i++)//有一行标题
                                {
                                    CAS200_dataGridView.Rows[i].Cells[0].Value = arrtmp[4 * (i + 1) + 0];
                                    CAS200_dataGridView.Rows[i].Cells[1].Value = arrtmp[4 * (i + 1) + 1];
                                    CAS200_dataGridView.Rows[i].Cells[2].Value = arrtmp[4 * (i + 1) + 2];
                                    CAS200_dataGridView.Rows[i].Cells[3].Value = arrtmp[4 * (i + 1) + 3];
                                }
                                MessageBox.Show("CA310数据导入OK！", "提示：");
                            }
                            catch
                            {
                                MessageBox.Show("CA310数据导入时发生错误！", "提示：");
                            }
                        }
                    }
                    break;
                case "btn_CAS200_Clean":
                    {
                        DialogResult dr = MessageBox.Show("确认清空列表数据吗？", "系统提示", MessageBoxButtons.OKCancel);
                        if (dr == DialogResult.OK)
                        {
                            this.CAS200_dataGridView.Rows.Clear();
                        }
                        else {; }
                    }
                    break;
                case "btn_CAS200_Delect":
                    {
                        int Current_Index, Row_Accum;
                        Current_Index = this.CAS200_dataGridView.SelectedCells[0].RowIndex;
                        DataGridViewRow Row1 = CAS200_dataGridView.Rows[Current_Index];
                        this.CAS200_dataGridView.Rows.Remove(Row1);
                        this.CAS200_dataGridView.Rows[Current_Index].Selected = false;
                        Row_Accum = this.CAS200_dataGridView.Rows.Count - 1;
                        for (Current_Index = 0; Current_Index < Row_Accum; Current_Index++)
                        {
                            this.CAS200_dataGridView.Rows[Current_Index].Cells[0].Value = Current_Index + 1;//序号
                        }
                        this.CAS200_dataGridView.Rows[Row_Accum - 1].Selected = true;
                        CAS200_dataGridView.FirstDisplayedScrollingRowIndex = CAS200_dataGridView.RowCount - 1;
                    }
                    break;

                case "btn_CAS200_Stop":
                    {
                        T20.Enabled = false;
                        measure_all_gray_flag = false;
                        measure_node_flag = false;
                        CAS200_Measure_Count = 0;
                        CAS200_Measure_Count_High2Low = 255;
                    }
                    break;
                //case "btn_CAS200_Start":
                //    {
                //        string strLine = Convert.ToString(text_CE_data.Text);
                //        string[] arr = strLine.Split(','); //以逗号分割，添加到数组
                //                                           //  Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
                //        CAS200_Measure_Count = 0;
                //        CAS200_Measure_Gray = 255;
                //        CA200_Measure_CE = byte.Parse((Convert.ToInt32(arr[arr.Length - 1], 16).ToString()));
                //        T3.Enabled = true;
                //        T3.Interval = int.Parse(CAS200_txt1.Text);//延时
                //    }
                //     break;



                //case "btn_CAS200_Start":
                //    {

                //        CAS200_Measure_Count = 0;

                //        CAS200_Measure_Gray = VTDR7120_51Reg_trackBar.Value;

                //        int[] Point_VTDR7120_tmp = new int[25] { 255, 223, 191, 159, 127, 111, 95, 79, 71, 63, 55, 47, 39, 35, 31, 27, 23, 19, 15, 11, 7, 5, 3, 1,0 };

                //        for (CAS200_Measure_Count=0; CAS200_Measure_Count<25; CAS200_Measure_Count++)
                //        {
                //            T3.Enabled = true;
                //            T3.Interval = int.Parse(CAS200_txt1.Text);//延时
                //                                                      //if (cbx_follow_51_points.Checked)
                //                                                      //{
                //                                                      //    VTDR7120_RegWR_Click(VTDR7120_51Reg_W, e);
                //                                                      //}
                //            VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120_tmp[CAS200_Measure_Count].ToString() + ".dsc_0001.bmp");
                //            Thread.Sleep(150);
                //            btn_CAS200_Synt_Click(btn_CAS200_Measure, null);
                //            Thread.Sleep(50);

                //        }
                //        T3.Enabled =false;

                //    }
                //    break;


                case "btn_CAS200_Start":
                    {
                        if (cbx_follow_gamma_points.Checked == true)  //选择了绑点
                        {
                            measure_node_flag = true;
                            while (measure_node_flag)
                            {
                                if (CAS200_Measure_Count > 24)
                                {
                                    textBox1.Text += "绑点数据量测完毕\r\n";
                                    measure_node_flag = false;
                                    CAS200_Measure_Count = 0;
                                }
                                else
                                {
                                    VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120_tmp[CAS200_Measure_Count] + ".dsc_0001.bmp");
                                    T20_Tick_start();
                                }
                                CAS200_Measure_Count++;
                            }

                        }

                        if (rbt_OtherMeasure.Checked == true)//选择全灰阶
                        {
                            CAS200_Measure_Count_High2Low = 255;//从最高灰阶开始测
                            measure_all_gray_flag = true;
                            while (measure_all_gray_flag)
                            {
                                if (CAS200_Measure_Count_High2Low < 0)
                                {
                                    textBox1.Text += "绑点数据量测完毕\r\n";
                                    measure_all_gray_flag = false;
                                    CAS200_Measure_Count_High2Low = 255;//归顶
                                }
                                else
                                {
                                    VTDR7120_btnPrevPic_Run("A" + CAS200_Measure_Count_High2Low + ".dsc_0001.bmp");
                                    T20_Tick_start();
                                }
                                CAS200_Measure_Count_High2Low--;
                            }

                        }
                    }
                    break;

                default: break;
            }
        }
        private void btnCal_Click(object sender, EventArgs e)
        {

            if (Vesa_Check.Checked == true)
            {
                //OLED_Show_Vesa_Pic_Click(btnblack, e);
                VTDR7120_btnPrevPic_Run("A0" + ".dsc_0001.bmp");
            }
            else
            {
                OLED_Show_Click(btnblack, e);
            }
            ca310info.Visible = true;
            try
            {
                Ca310Obj.CA310_Connect();
                Ca310Obj.CA310_Initial(byte.Parse(MainForm.CA310_Channel.Text));

                /*btnAutogamma350.Enabled = true;
                btnAutogammas350.Enabled = true;*/

                CAS200_dataGridView.Enabled = true;
                btn_CAS200Save.Enabled = true;
                btn_CAS200_Measure.Enabled = true;
                btn_CAS200_Clean.Enabled = true;
                btn_CAS200_Delect.Enabled = true;
                gBx_CAS200_Auto_Test.Enabled = true;
            }
            catch (Exception EX)
            {
                MessageBox.Show("CA310 Connect Fail!!" + EX.Message);
            }

            btnCal_manual.Text = "0Cal";
            ca310info.Visible = false;
            ca310info.Enabled = true;
            textBox1.Text += "校零完成！";
        }

        int stop_flag = 1;

        //快速310测试
        string sss = "";//存310数据
        private void fast_310_write(object sender, EventArgs e)
        {  //调用310测试函数

            pcs_CA310();
            sss = sss + iii + 1 + ":" + auto_lum.ToString() + auto_x.ToString() + auto_y.ToString() + "\r\n";//文本会显示在

        }
        int iii = 1;//如果clear()后就，则将iii重新设置为1
        private void pcs_CA310()
        {
            //if (stop_flag == 0)
            //{ T18.Enabled = false; }
            //else { }

            try
            {
                MainForm.Msr_CASDK();
                auto_lum = MainForm.CASDK_LUM;
                auto_x = MainForm.CASDK_x;
                auto_y = MainForm.CASDK_y;
            }
            catch
            {
                MessageBox.Show("请校准Senser！");
                //T17.Enabled = false;
                //return false;
            }
            iii++;//记录此时用的
        }

        private void Msr_CA310()
        {
            //if (stop_flag == 0)
            //{ T18.Enabled = false; }
            //else { }

            try
            {
                MainForm.Msr_CASDK();
                auto_lum = MainForm.CASDK_LUM;
                auto_x = MainForm.CASDK_x;
                auto_y = MainForm.CASDK_y;
            }
            catch
            {
                MessageBox.Show("请校准Senser！");
                //T17.Enabled = false;
                //return false;
            }

        }
        //=================================LCD cfg function: OLED_Show_Click====end=================     
        private int adjust_num = 0;
        private string adjust_class = null;
        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色
        private double D_x, D_y;
        //private double lum_off, x_off, y_off;
        private int index = 0;
        //private int flag1 = 1;
        //private int flag2 = 1;
        //private int flag3 = 1;
        private int adjust_Rnum = 0;
        private int adjust_Gnum = 0;
        private int adjust_Bnum = 0;
        private int adjust_l = 0;
        private int adjust_x = 0;
        private int adjust_y = 0;
        //private int step_l = 1;
        //private int step_m = 5;
        //private int step_h = 12;
        Gamma_Addr GAMMAs = new Gamma_Addr();
        private ushort[] gamma_r = new ushort[31];
        private ushort[] gamma_g = new ushort[31];
        private ushort[] gamma_b = new ushort[31];
        private double lum_off, x_off, y_off;
        private double R_x = 0.67;//
        private double R_y = 0.33;
        private double G_x = 0.22;
        private double G_y = 0.71;
        private void btnBack_Click(object sender, EventArgs e)
        {
            MainForm.comPort.DataReceived -= new SerialDataReceivedEventHandler(SerialPort1_DataReceived);//移除本窗口串口处理函数
            MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(MainForm.SerialPort1_DataReceived);//
            MainForm.Show();
            this.Hide();
            frm_new_vtdr6110 = 0;
        }
        private double B_x = 0.14;
        private double B_y = 0.06;
        //浏览图片
        private void btnReload_Click(object sender, EventArgs e)    //载入画面按键  选择文件夹
        {
            FolderBrowserDialog fldb = new FolderBrowserDialog();
            fldb.ShowNewFolderButton = false;
            DialogResult res = fldb.ShowDialog();
            if (res != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("没选择任何文件夹.");
                return;
            }
            string path = fldb.SelectedPath;
            if (!Directory.Exists(path))
            {
                MessageBox.Show("文件夹不存在.");
                return;
            }
            DirectoryInfo di = new DirectoryInfo(path);
            this.listBox3_BMPFile.Items.Clear();
            this.CreateListItem(di);//递归加载文件夹里的所有图片
            textBox2.Text = path;
        }
        /// <summary>
        /// 递归文件夹，把文件夹里所有后缀类似图片的文件，加入listbox
        /// </summary>
        /// <param name="di"></param>
        private void CreateListItem(DirectoryInfo di)
        {
            foreach (DirectoryInfo childDi in di.GetDirectories())
            {
                this.CreateListItem(childDi);
            }
            foreach (FileInfo fi in di.GetFiles())
            {
                if (ImageType.Contains(fi.Extension))//找到一个图片(如果用户手贱把一个excel文件后缀改成jpeg没办法)
                {
                    this.listBox3_BMPFile.Items.Add(new MyImage(fi.FullName));
                }
            }
        }
        private void lstImage_Click(object sender, EventArgs e)
        {
            if (listBox3_BMPFile.SelectedItem == null)
            {
                return;
            }
            MyImage selectedImg = (MyImage)listBox3_BMPFile.SelectedItem;
            Image img = new Bitmap(selectedImg.Path);
            pictureBox1.Image = img;
        }


        System.DateTime TimeNow2 = new DateTime();
        TimeSpan TimeCount2 = new TimeSpan();

        //private void btnPrevPic_Click(object sender, EventArgs e)
        //{
        //    FileStream aFile;
        //    Int32 m_txlen = 0;

        //    int HACT_True;
        //    int VACT_True;
        //    int j;
        //    TimeNow2 = DateTime.Now; //开始计时

        //    byte[] TemFileContent = new byte[512 * 4000 + 100];
        //    int ByteReaded = 0x00;

        //    string FileName = textBox2.Text + '\\' + listBox3_BMPFile.SelectedItem.ToString();

        //    aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        //    ByteReaded = aFile.Read(TemFileContent, 0, 54);

        //    HACT_True = ((TemFileContent[19]) << 8) + TemFileContent[18];
        //    VACT_True = ((TemFileContent[23] << 8) + TemFileContent[22]);
        //    if (MainForm.HACT.Value != HACT_True)
        //    {
        //        textBox1.Text += "图片宽度与设定不符\r\n";
        //        return;
        //    }

        //    if ((MainForm.Dis_mode.SelectedIndex == 1)) //(Dis_mode.SelectedIndex == 1):MIPI 模式，因为下位机仅对MIPI模式做了优化
        //    {
        //        //------------20180903---------------
        //        try
        //        {   //bd 5a a5 9DF0-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
        //            //BD A5 5A 9DF0-----提前下个标志位告诉下位机开始 快速 送图了
        //            TemFileContent[0] = 0xbd; TemFileContent[1] = 0xa5; TemFileContent[2] = 0x5a; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
        //            MainForm.comPort.Write(TemFileContent, 0, 5);
        //        }
        //        catch
        //        {
        //            MessageBox.Show("串口有误，请检查", "错误");
        //            return;
        //        }
        //        //-----------------------------------
        //        try
        //        {
        //            j = 0;
        //            int x, y, s = 0;
        //            x = 512 * 4000; //单次传输数量
        //            y = (VACT_True * HACT_True * 3 / x); //传输次数
        //            if ((VACT_True * HACT_True * 3 % x) != 0)
        //                y++;
        //            {
        //                //aFile.Seek(54, SeekOrigin.Begin);
        //                while (j < y)
        //                {
        //                    //if (HACT_True % 4 != 0)
        //                    //    aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
        //                    //else
        //                    //    aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);
        //                    aFile.Seek((j) * x + 54, SeekOrigin.Begin);

        //                    ByteReaded = aFile.Read(TemFileContent, 0, x);

        //                    try
        //                    {
        //                        MainForm.comPort.Write(TemFileContent, 0, ByteReaded);
        //                    }
        //                    catch
        //                    {
        //                        MessageBox.Show("串口有误，请检查", "错误");
        //                        break;
        //                    }

        //                    progressBar1.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
        //                    label14.Text = progressBar1.Value.ToString() + "%";
        //                    Application.DoEvents();
        //                    j++;
        //                }

        //                TemFileContent[0] = 0x5A;
        //                try
        //                {
        //                    MainForm.comPort.Write(TemFileContent, 0, 1);
        //                }
        //                catch
        //                {
        //                    MessageBox.Show("串口有误，请检查", "错误");
        //                }

        //                aFile.Close();
        //            }
        //        }
        //        catch
        //        {
        //            MessageBox.Show("请选择文件夹", "错误");
        //        }
        //    }
        //    else
        //    {
        //        //------------20180808---------------
        //        try
        //        { //5a a5 9DF0731A-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
        //            TemFileContent[0] = 0xbd; TemFileContent[1] = 0x5a; TemFileContent[2] = 0xa5; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
        //            MainForm.comPort.Write(TemFileContent, 0, 5);
        //        }
        //        catch
        //        {
        //            MessageBox.Show("串口有误，请检查", "错误");
        //            return;
        //        }
        //        //-----------------------------------
        //        try
        //        {
        //            j = 1;
        //            //if ((HACT_True == ((TemFileContent[19] << 8) + (TemFileContent[18]))) && (Convert.ToInt32(VACT.Value) == (TemFileContent[23] << 8) + (TemFileContent[22])))//BMP图片水平大小
        //            {
        //                aFile.Seek(54, SeekOrigin.Begin);
        //                while (j <= VACT_True)
        //                {
        //                    if (HACT_True % 4 != 0)
        //                        aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
        //                    else
        //                        aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);


        //                    ByteReaded = aFile.Read(TemFileContent, 0, HACT_True * 3); // 

        //                    try
        //                    {
        //                        MainForm.comPort.Write(TemFileContent, 0, ByteReaded);
        //                    }
        //                    catch
        //                    {
        //                        MessageBox.Show("串口有误，请检查", "错误");
        //                        break;
        //                    }
        //                    m_txlen += ByteReaded;
        //                    progressBar1.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
        //                    label14.Text = progressBar1.Value.ToString() + "%";
        //                    Application.DoEvents();//重点，必须加上，否则父子窗体都假死
        //                    j++;
        //                }

        //                TemFileContent[0] = 0x5A;
        //                try
        //                {
        //                    MainForm.comPort.Write(TemFileContent, 0, 1);
        //                }
        //                catch
        //                {
        //                    MessageBox.Show("串口有误，请检查", "错误");
        //                    return;
        //                }

        //                aFile.Close();
        //            }
        //            /*
        //            else
        //            {
        //                MessageBox.Show("BMP分辨率非法");
        //            }*/
        //        }
        //        catch
        //        {
        //            textBox1.Text += "啥图片都没显示";
        //            textBox1.Select(textBox1.Text.Length, 0);
        //            textBox1.ScrollToCaret();
        //        }
        //    }


        //    TimeCount2 = DateTime.Now - TimeNow2;
        //    textBox1.Text = string.Format("{0:00}:{1:00}", TimeCount2.Seconds, TimeCount2.Milliseconds);
        //}

        private void btnPrevPic_Click(object sender, EventArgs e)
        {
            FileStream aFile;
            Int32 m_txlen = 0;

            int HACT_True;
            int VACT_True;
            int j;
            TimeNow2 = DateTime.Now; //开始计时

            byte[] TemFileContent = new byte[512 * 4000 + 100];
            int ByteReaded = 0x00;

            string FileName = textBox2.Text + '\\' + listBox3_BMPFile.SelectedItem.ToString();

            aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            ByteReaded = aFile.Read(TemFileContent, 0, 54);

            HACT_True = ((TemFileContent[19]) << 8) + TemFileContent[18];
            VACT_True = ((TemFileContent[23] << 8) + TemFileContent[22]);
            if (MainForm.HACT.Value != HACT_True)
            {
                textBox1.Text += "图片宽度与设定不符\r\n";
                return;
            }
            if ((MainForm.BridgeChipModel.SelectedIndex == 1) && (MainForm.Dis_mode.SelectedIndex == 1))
            // if ((MainForm.Dis_mode.SelectedIndex == 1)) //(Dis_mode.SelectedIndex == 1):MIPI 模式，因为下位机仅对MIPI模式做了优化
            {
                //------------20180903---------------
                try
                {   //bd 5a a5 9DF0-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
                    //BD A5 5A 9DF0-----提前下个标志位告诉下位机开始 快速 送图了
                    TemFileContent[0] = 0xbd; TemFileContent[1] = 0xa5; TemFileContent[2] = 0x5a; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
                    MainForm.comPort.Write(TemFileContent, 0, 5);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                    return;
                }
                //-----------------------------------
                try
                {
                    j = 0;
                    int x, y, s = 0;
                    x = 512 * 4000; //单次传输数量
                    y = (VACT_True * HACT_True * 3 / x); //传输次数
                    if ((VACT_True * HACT_True * 3 % x) != 0)
                        y++;
                    {
                        //aFile.Seek(54, SeekOrigin.Begin);
                        while (j < y)
                        {
                            if (HACT_True % 4 != 0)
                                aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
                            else
                                aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);
                            aFile.Seek((j) * x + 54, SeekOrigin.Begin);

                            ByteReaded = aFile.Read(TemFileContent, 0, x);

                            try
                            {
                                MainForm.comPort.Write(TemFileContent, 0, ByteReaded);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                                break;
                            }

                            progressBar1.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
                            label14.Text = progressBar1.Value.ToString() + "%";
                            Application.DoEvents();
                            j++;
                        }

                        TemFileContent[0] = 0x5A;
                        try
                        {
                            MainForm.comPort.Write(TemFileContent, 0, 1);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }

                        aFile.Close();
                    }
                }
                catch
                {
                    MessageBox.Show("请选择文件夹", "错误");
                }
            }
            else
            {
                //------------20180808---------------
                try
                { //5a a5 9DF0731A-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
                    TemFileContent[0] = 0xbd; TemFileContent[1] = 0x5a; TemFileContent[2] = 0xa5; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
                    MainForm.comPort.Write(TemFileContent, 0, 5);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                    return;
                }
                //-----------------------------------
                try
                {
                    j = 1;
                    //if ((HACT_True == ((TemFileContent[19] << 8) + (TemFileContent[18]))) && (Convert.ToInt32(VACT.Value) == (TemFileContent[23] << 8) + (TemFileContent[22])))//BMP图片水平大小
                    {
                        aFile.Seek(54, SeekOrigin.Begin);
                        while (j <= VACT_True)
                        {
                            if (HACT_True % 4 != 0)
                                aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
                            else
                                aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);


                            ByteReaded = aFile.Read(TemFileContent, 0, HACT_True * 3); // 

                            try
                            {
                                MainForm.comPort.Write(TemFileContent, 0, ByteReaded);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                                break;
                            }
                            m_txlen += ByteReaded;
                            progressBar1.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
                            label14.Text = progressBar1.Value.ToString() + "%";
                            Application.DoEvents();//重点，必须加上，否则父子窗体都假死
                            j++;
                        }

                        TemFileContent[0] = 0x5A;
                        try
                        {
                            MainForm.comPort.Write(TemFileContent, 0, 1);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                            return;
                        }

                        aFile.Close();
                    }
                    /*
                    else
                    {
                        MessageBox.Show("BMP分辨率非法");
                    }*/
                }
                catch
                {
                    textBox1.Text += "啥图片都没显示";
                    textBox1.Select(textBox1.Text.Length, 0);
                    textBox1.ScrollToCaret();
                }
            }


            TimeCount2 = DateTime.Now - TimeNow2;
            //textBox1.Text = string.Format("{0:00}:{1:00}", TimeCount2.Seconds, TimeCount2.Milliseconds);
        }
        public class MyImage
        {
            public MyImage(string p)
            {
                this.Path = p;
            }
            public string Path { get; set; }
            public override string ToString()
            {
                if (Path == null)
                {
                    return null;
                }
                return System.IO.Path.GetFileName(this.Path);
            }
        }
        private void VTDR7120_GAMMA_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;

            //-------这句话做什么用的
            //if(frm_new_vtdr6110 == 0)
            //{
            //    button3_Click(VTDR7120_select_gamma, e);
            //    System.Threading.Thread.Sleep(100);
            //    frm_new_vtdr6110 = 1;
            //}

            //if (frm_new_vtdr6110 == 0)
            //{
            //    Write_gamma_x(VTDR7120_select_gamma, e);
            //    System.Threading.Thread.Sleep(100);
            //    frm_new_vtdr6110 = 1;
            //}


            //每调一次都要写这个
            //Write_gamma_x(VTDR7120_select_gamma, e);
            //System.Threading.Thread.Sleep(100);

            Send_buf = new byte[57];
            Setting.TempRecord.cmdLen = 57;
            Send_buf[2] = 52;
            Send_buf[3] = 0;
            Send_buf[0] = 0x60; //VTDR7120


            switch (btnTmp.Name)
            {
                case "VTDR7120_GammaR_Red":
                    {
                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] = 0x00;                            //红色red
                                                                       // Send_buf[4] = 0x00;
                        Send_buf[4] = (byte)(VTDR7120_Gamma_Group.Value);
                        Setting.TempRecord.VTDR7120CmdType = 0x03;       //      1
                    }
                    break;
                case "VTDR7120_GammaR_Green":
                    {
                        Send_buf[1] = 0x09;                         //  读Gamma
                        Send_buf[3] = 0x42;                        //绿色 green
                        //Send_buf[4] = 0x00;
                        Send_buf[4] = (byte)(VTDR7120_Gamma_Group.Value);
                        Setting.TempRecord.VTDR7120CmdType = 0x04;   //      4
                    }
                    break;
                case "VTDR7120_GammaR_Blue": //              9
                    {
                        Send_buf[1] = 0x09;                         //   读Gamma
                        Send_buf[3] = 0x81;                        //   blue  
                        //Send_buf[4] = 0x00;
                        Send_buf[4] = (byte)(VTDR7120_Gamma_Group.Value);
                        Setting.TempRecord.VTDR7120CmdType = 0x05;   //      5
                    }
                    break;
                //--------------------------------------
                case "VTDR7120_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;                       //写Gamma
                        Send_buf[3] = 0x00;                       //红色1
                        //Send_buf[4] = 0x00;
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR7120_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R255.Value.ToString())) & 0xff);
                        Thread.Sleep(10); //1秒=1000毫秒，
                    }
                    break;

                case "VTDR7120_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x42;
                        // Send_buf[4] = 0x04;
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR7120_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G255.Value.ToString())) & 0xff);
                        Thread.Sleep(10); //1秒=1000毫秒，
                    }
                    break;

                case "VTDR7120_GammaW_Blue":     //      8
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x81;
                        //Send_buf[4] = 0x08;
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR7120_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B255.Value.ToString())) & 0xff);
                        Thread.Sleep(10); //1秒=1000毫秒，
                    }
                    break;
                #region
                //没有用
                case "UP_READ_GAMMA":
                    {
                        Send_buf[1] = 0x0A;                       //写Gamma
                        Send_buf[3] = 0x00;                       //红色1
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR7120_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR7120_R255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR7120_R255.Value.ToString())) & 0xff);


                    }
                    break;

                //没有用
                case "UP_GREEN_GAMMA":
                    {
                        Send_buf[1] = 0x0A;
                        Send_buf[3] = 0x42;                       //绿色1
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR7120_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR7120_G255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR7120_G255.Value.ToString())) & 0xff);

                    }
                    break;

                //没有用
                case "UP_BLUE_GAMMA":     //      8
                    {
                        Send_buf[1] = 0x0A;
                        Send_buf[3] = 0x81;
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR7120_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR7120_B255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR7120_B255.Value.ToString())) & 0xff);

                    }
                    break;
                #endregion

                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[55], out Send_buf[56]);
            try
            {
                VTDR7120_0XFE_XX = 0x00;
                MainForm.comPort.Write(Send_buf, 0, 57);   //VTDR7120
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
                return;
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
            //frmHelp.T1.Enabled = false;
            //frmHelp.T1.Interval = 2000;
            //frmHelp.T1.Enabled = true;
        }
        private void VTDR7120_RegWR_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Int32 DataNum;
            string strLine = Convert.ToString(VTDR7120_txtRegData.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组

            switch (btnTmp.Name)
            {
                case "VTDR7120_RegW":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x60;//VTDR7120

                        if (VTDR7120_rbt_LP.Checked == true)
                        { Send_buf[1] = 0x01; }
                        else if (VTDR7120_rbt_HS.Checked == true)
                        { Send_buf[1] = 0x81; }

                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "VTDR7120_51Reg_W":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x60;
                        //Send_buf[1] = 0x03;
                        Send_buf[1] = 0x01;
                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "VTDR7120_RegR":
                    {
                        Setting.TempRecord.VTDR7120CmdType = 0x02;
                        try
                        {
                            DataNum = Convert.ToInt32(VTDR7120_txtDataNum.Text) + 1;
                            Setting.TempRecord.cmdLen = DataNum + 5;
                            Send_buf = new byte[DataNum + 5];
                            Send_buf[0] = 0x60; //VTDR7120
                            Send_buf[1] = 0x02;
                            Send_buf[2] = byte.Parse(Convert.ToString(DataNum));
                            Send_buf[3] = byte.Parse((Convert.ToInt32(arr[0], 16)).ToString());  //cmd
                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + DataNum - 2], out Send_buf[5 + DataNum - 1]);
                        }
                        catch
                        {
                            MessageBox.Show("读取长度有误，请检查", "错误");
                            break;
                        }
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + DataNum);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "Demura_on":
                    {
                        strLine = Convert.ToString("59,09");
                        arr = strLine.Split(','); //以逗号分割，添加到数组

                        Setting.TempRecord.cmdLen = 2 + 5;
                        Send_buf = new byte[2 + 5];
                        Send_buf[0] = 0x60;//VTDR7120
                        Send_buf[1] = 0x01;//写寄存器

                        Send_buf[2] = 2;//数据长度
                        Send_buf[3 + 0] = 0x59;
                        Send_buf[3 + 1] = 0x09;

                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                        textBox1.Text = textBox1.Text + "Demura on \r\n";
                    }
                    break;
                case "Demura_off":
                    {
                        strLine = Convert.ToString("59,00");
                        arr = strLine.Split(','); //以逗号分割，添加到数组

                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x60;//VTDR7120
                        Send_buf[1] = 0x01;

                        Send_buf[2] = 2;
                        Send_buf[3 + 0] = 0x59;
                        Send_buf[3 + 1] = 0x00;

                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                        textBox1.Text = textBox1.Text + "Demura off \r\n";
                    }
                    break;
                default: break;
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }

        private void VTDR7120_trackBar_Scroll(object sender, EventArgs e)
        {
            VTDR7120_label.Text = VTDR7120_51Reg_trackBar.Value.ToString() + "阶";
            VTDR7120_txtRegData.Text = "51," + (Convert.ToByte((VTDR7120_51Reg_trackBar.Value) >> 8)).ToString("X2") + "," + (Convert.ToByte((VTDR7120_51Reg_trackBar.Value) & 0xff)).ToString("X2");
            VTDR7120_RegWR_Click(VTDR7120_51Reg_W, e);
            // VTDR7120_RegWR_Click(VTDR7120_RegW, e);
        }

        //page页烧录和Demura的一些操作
        private void VTDR7120_Others_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;

            Send_buf[0] = 0x60;
            Send_buf[2] = 0x02;//返回两个值  

            switch (btnTmp.Name)
            {
                //rbt_otp_gamma  无效按钮
                //rbt_otp_P3 是gamma按钮
                case "VTDR7120_OTP":
                    {   //暂时注释掉
                        ////VTDR7120_0XFE_XX = 0x00;
                        //Send_buf[1] = 0x0D;
                        //if (rbt_otp_P0.Checked == true)
                        //{ Send_buf[3] = 0x0F; }//OK
                        //else if (rbt_otp_P1.Checked == true)
                        //{ Send_buf[3] = 0x1B; }//OK
                        //else if (rbt_otp_P2.Checked == true)
                        //{ Send_buf[3] = 0x1C; }//OK
                        //else if (rbt_otp_P4.Checked == true)
                        //{ Send_buf[3] = 0x1A; }//OK
                        //else if (rbt_otp_P5.Checked == true)
                        //{ Send_buf[3] = 0x1D; }//OK
                        //else if (rbt_otp_P7.Checked == true)
                        //{ Send_buf[3] = 0x1E; }//OK
                        //else if (rbt_otp_P8.Checked == true)
                        //{ Send_buf[3] = 0x1F; }//OK
                        //else if (rbt_otp_P3.Checked == true)  //是gamma么
                        //{ Send_buf[3] = 0x2A; }//--------//OK
                        //else if (rbt_otp_P6.Checked == true)
                        //{ Send_buf[3] = 0x2B; }//---------下位机   
                        //else if (rbt_otp_all.Checked == true)
                        //{ Send_buf[3] = 0x0E; }//OK
                        //else if (rbt_otp_gamma.Checked == true)
                        //{ Send_buf[3] = 0x0D; }
                    }
                    break;
                //case "VTDR7120_W2810":   //作用不明
                //    {
                //        VTDR7120_0XFE_XX = 0x00;
                //        Send_buf[1] = 0x1F;
                //    }
                //    break;

                //Demura部分

                //VTDR6100
                //case "Read_Flash_ID":         //读Flash ID
                //    {
                //        VTDR7120_0XFE_XX = 0x00;
                //        Send_buf[1] = 0x20;
                //    }
                //    break;

                //case "Erase_Flash":         //擦除Flash
                //    {
                //        VTDR7120_0XFE_XX = 0x00;
                //        Send_buf[1] = 0x21;
                //        textBox1.Text = textBox1.Text + "Please Wait for 50 seconds\r\n";
                //    }
                //    break;

                //==============VTDR_7120 新的Demura 流程==============
                case "btn_Read_Flash_ID":         //读Flash ID
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x20;
                    }
                    break;
                case "btn_Erase_Flash_IC":         //擦除Flash
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x21;
                        textBox1.Text = textBox1.Text + "Please Wait for 5 seconds\r\n";
                    }
                    break;


                case "btn_Flash_Program_Demura_Data_1":         //进入编程
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x29;

                    }
                    break;

                case "btn_Flash_Program_Demura_Data_2":         //进入编程
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x30;

                    }
                    break;

                case "btn_Reset_And_Reload_Demura_Data":         //Reset
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x31;
                    }
                    break;
                //==========================================


                case "Flash_Status":         //确认Flash Status
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x22;
                        //textBox1.Text = textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "Check_Flash":         //确认Flash Status
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x23;
                        Setting.TempRecord.cmdLen = 13;////CRC 特殊处理
                        //textBox1.Text = textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "Five_Step":         //确认Flash Status
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x24;
                        //Setting.TempRecord.cmdLen = 14;////CRC 特殊处理
                        //textBox1.Text = textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "OTP_Flash":         //确认Flash Status
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x25;
                        textBox1.Text = textBox1.Text + "OTP Please Wait for 40 seconds\r\n";
                    }
                    break;
                case "CRC_check":
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x26;
                        Setting.TempRecord.cmdLen = 14;////CRC 特殊处理
                        textBox1.Text = textBox1.Text + "CRC_check\r\n";
                    }
                    break;
                case "button4":
                    {
                        VTDR7120_0XFE_XX = 0x00;
                        Send_buf[1] = 0x27;///reset 
                        textBox1.Text = textBox1.Text + "reset system \r\n";
                    }
                    break;
                default:
                    break;
            }

            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                MainForm.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }
        //private int[] Parttern_VTDR7120 = new int[14] { 255, 223, 191, 127, 111, 79, 63, 55, 47, 39, 35, 31, 11, 3 };
        private int[] Parttern_VTDR7120 = new int[24] { 255, 223, 191, 159, 127, 111, 95, 79, 71, 63, 55, 47, 39, 35, 31, 27, 23, 19, 15, 11, 7, 5, 3, 1 };

        //15绑点数据计算
        //private void btnCalculate_VTDR7120_Click(object sender, EventArgs e)
        //{
        //    txtVT_255.Text = (Math.Pow((Parttern_VTDR7120[0] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_223.Text = (Math.Pow((Parttern_VTDR7120[1] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_191.Text = (Math.Pow((Parttern_VTDR7120[2] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_127.Text = (Math.Pow((Parttern_VTDR7120[3] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_111.Text = (Math.Pow((Parttern_VTDR7120[4] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_79.Text = (Math.Pow((Parttern_VTDR7120[5] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_63.Text = (Math.Pow((Parttern_VTDR7120[6] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_55.Text = (Math.Pow((Parttern_VTDR7120[7] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_47.Text = (Math.Pow((Parttern_VTDR7120[8] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_39.Text = (Math.Pow((Parttern_VTDR7120[9] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_35.Text = (Math.Pow((Parttern_VTDR7120[10] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_31.Text = (Math.Pow((Parttern_VTDR7120[11] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_11.Text = (Math.Pow((Parttern_VTDR7120[12] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //    txtVT_3.Text = (Math.Pow((Parttern_VTDR7120[13] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        //}



        //25绑点数据计算
        private void btnCalculate_VTDR7120_Click(object sender, EventArgs e)
        {
            txtVT_255.Text = (Math.Pow((Point_VTDR7120[0] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_223.Text = (Math.Pow((Point_VTDR7120[1] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_191.Text = (Math.Pow((Point_VTDR7120[2] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_159.Text = (Math.Pow((Point_VTDR7120[3] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_127.Text = (Math.Pow((Point_VTDR7120[4] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_111.Text = (Math.Pow((Point_VTDR7120[5] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_95.Text = (Math.Pow((Point_VTDR7120[6] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_79.Text = (Math.Pow((Point_VTDR7120[7] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_71.Text = (Math.Pow((Point_VTDR7120[8] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_63.Text = (Math.Pow((Point_VTDR7120[9] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_55.Text = (Math.Pow((Point_VTDR7120[10] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_47.Text = (Math.Pow((Point_VTDR7120[11] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_39.Text = (Math.Pow((Point_VTDR7120[12] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_35.Text = (Math.Pow((Point_VTDR7120[13] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_31.Text = (Math.Pow((Point_VTDR7120[14] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_27.Text = (Math.Pow((Point_VTDR7120[15] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_23.Text = (Math.Pow((Point_VTDR7120[16] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_19.Text = (Math.Pow((Point_VTDR7120[17] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_15.Text = (Math.Pow((Point_VTDR7120[18] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_11.Text = (Math.Pow((Point_VTDR7120[19] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_7.Text = (Math.Pow((Point_VTDR7120[20] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_5.Text = (Math.Pow((Point_VTDR7120[21] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_3.Text = (Math.Pow((Point_VTDR7120[22] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_1.Text = (Math.Pow((Point_VTDR7120[23] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        }
        private void T17_Tick(object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
            Msr_CA310();

            if ((auto_lum < (D_lum[index] + lum_off)) && (auto_lum > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((auto_y < (D_y + y_off)) && (auto_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((auto_x < (D_x + x_off)) && (auto_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T17.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index == 14)
                {
                    textBox1.Text = textBox1.Text + "VTDR7120 gamma调试完毕!\r\n";
                }
                if (index < 14)
                {
                    switch (index)
                    {
                        case 1:
                            lum_off = Convert.ToDouble(textVT_223_off.Text);
                            break;

                        case 2:
                            lum_off = Convert.ToDouble(textVT_191_off.Text);
                            break;

                        case 3:
                            lum_off = Convert.ToDouble(textVT_127_off.Text) * Convert.ToDouble(txtVT_127.Text) / 100;
                            break;

                        case 4:
                            lum_off = Convert.ToDouble(textVT_111_off.Text) * Convert.ToDouble(txtVT_111.Text) / 100;
                            break;

                        case 5:
                            lum_off = Convert.ToDouble(textVT_79_off.Text) * Convert.ToDouble(txtVT_79.Text) / 100;
                            break;

                        case 6:
                            lum_off = Convert.ToDouble(textVT_63_off.Text) * Convert.ToDouble(txtVT_63.Text) / 100;
                            break;

                        case 7:
                            lum_off = Convert.ToDouble(textVT_55_off.Text) * Convert.ToDouble(txtVT_55.Text) / 100;
                            break;

                        case 8:
                            lum_off = Convert.ToDouble(textVT_47_off.Text) * Convert.ToDouble(txtVT_47.Text) / 100;
                            break;

                        case 9:
                            lum_off = Convert.ToDouble(textVT_39_off.Text) * Convert.ToDouble(txtVT_39.Text) / 100;
                            break;

                        case 10:
                            lum_off = Convert.ToDouble(textVT_35_off.Text) * Convert.ToDouble(txtVT_35.Text) / 100;
                            break;

                        case 11:
                            lum_off = Convert.ToDouble(textVT_31_off.Text) * Convert.ToDouble(txtVT_31.Text) / 100;
                            break;
                        case 12:
                            {
                                lum_off = Convert.ToDouble(textVT_11_off.Text) * Convert.ToDouble(txtVT_11.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;
                        case 13:
                            {
                                lum_off = Convert.ToDouble(textVT_3_off.Text) * Convert.ToDouble(txtVT_3.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;

                    }
                    numPatternR.Value = Parttern_VTDR7120[index];
                    numPatternG.Value = Parttern_VTDR7120[index];
                    numPatternB.Value = Parttern_VTDR7120[index];
                    OLED_Show_Click(btnPatternW, e);//写入Pattern参数
                    Thread.Sleep(10); //1秒=1000毫秒，
                    T17.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                Lr_t = R_y * ((auto_y - G_y) * (B_x - auto_x) + (auto_x - G_x) * (auto_y - B_y)) / B_y / ((auto_y - G_y) * (auto_x - R_x) + (auto_x - G_x) * (R_y - auto_y));
                Lb_t = 1.0;
                Lg_t = G_y * ((auto_y - R_y) * (B_x - auto_x) + (auto_x - R_x) * (auto_y - B_y)) / B_y / ((auto_y - R_y) * (auto_x - G_x) + (auto_x - R_x) * (G_y - auto_y));
                lumr = auto_lum * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = auto_lum * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = auto_lum * Lb_t / (Lr_t + Lg_t + Lb_t);

                //try
                {
                    switch (index)
                    {
                        case 0:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R255.Value = VTDR7120_R255.Value - step_h;
                                        else VTDR7120_R255.Value = VTDR7120_R255.Value + step_h;
                                        adjust_Rnum = 0;
                                        if (VTDR7120_R255.Value >= 0x3FF)
                                            VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;
                                        /*if (VTDR7120_R255.Value <= VTDR7120_R223.Value)
                                            VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R255.Value = VTDR7120_R255.Value - step_l;
                                        else VTDR7120_R255.Value = VTDR7120_R255.Value + step_l;
                                        /*if (VTDR7120_R255.Value <= VTDR7120_R223.Value)
                                            VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;*/
                                        if (VTDR7120_R255.Value >= 0x3FF)
                                            VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G255.Value = VTDR7120_G255.Value - step_h;
                                        else VTDR7120_G255.Value = VTDR7120_G255.Value + step_h;
                                        adjust_Gnum = 0;
                                        if (VTDR7120_G255.Value >= 0x3FF)
                                            VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;
                                        /*if (VTDR7120_G255.Value <= VTDR7120_G223.Value)
                                            VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G255.Value = VTDR7120_G255.Value - step_l;
                                        else VTDR7120_G255.Value = VTDR7120_G255.Value + step_l;
                                        if (VTDR7120_G255.Value >= 0x3FF)
                                            VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;
                                        /*if (VTDR7120_G255.Value <= VTDR7120_G223.Value)
                                            VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B255.Value = VTDR7120_B255.Value - step_h;
                                        else VTDR7120_B255.Value = VTDR7120_B255.Value + step_h;
                                        adjust_Bnum = 0;
                                        if (VTDR7120_B255.Value >= 0x3FF)
                                            VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;
                                        /*if (VTDR7120_B255.Value <= VTDR7120_B223.Value)
                                            VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B255.Value = VTDR7120_B255.Value - step_l;
                                        else VTDR7120_B255.Value = VTDR7120_B255.Value + step_l;
                                        if (VTDR7120_B255.Value >= 0x3FF)
                                            VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;
                                        /*if (VTDR7120_B255.Value <= VTDR7120_B223.Value)
                                            VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }

                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 1:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R223.Value = VTDR7120_R223.Value - step_h;
                                        else VTDR7120_R223.Value = VTDR7120_R223.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R223.Value <= VTDR7120_R191.Value)
                                            VTDR7120_R223.Value = VTDR7120_R191.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R223.Value = VTDR7120_R223.Value - step_l;
                                        else VTDR7120_R223.Value = VTDR7120_R223.Value + step_l;
                                        /*if(VTDR7120_R223.Value <= VTDR7120_R191.Value)
                                            VTDR7120_R223.Value = VTDR7120_R191.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G223.Value = VTDR7120_G223.Value - step_h;
                                        else VTDR7120_G223.Value = VTDR7120_G223.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if(VTDR7120_G223.Value <= VTDR7120_G191.Value)
                                            VTDR7120_G223.Value = VTDR7120_G191.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G223.Value = VTDR7120_G223.Value - step_l;
                                        else VTDR7120_G223.Value = VTDR7120_G223.Value + step_l;
                                        /*if(VTDR7120_G223.Value <= VTDR7120_G191.Value)
                                            VTDR7120_G223.Value = VTDR7120_G191.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B223.Value = VTDR7120_B223.Value - step_h;
                                        else VTDR7120_B223.Value = VTDR7120_B223.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if(VTDR7120_B223.Value <= VTDR7120_B191.Value)
                                            VTDR7120_B223.Value = VTDR7120_B191.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B223.Value = VTDR7120_B223.Value - step_l;
                                        else VTDR7120_B223.Value = VTDR7120_B223.Value + step_l;
                                        /*if(VTDR7120_B223.Value <= VTDR7120_B191.Value)
                                            VTDR7120_B223.Value = VTDR7120_B191.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 2:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R191.Value = VTDR7120_R191.Value - step_h;
                                        else VTDR7120_R191.Value = VTDR7120_R191.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R191.Value <= VTDR7120_R159.Value)
                                            VTDR7120_R191.Value = VTDR7120_R159.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R191.Value = VTDR7120_R191.Value - step_l;
                                        else VTDR7120_R191.Value = VTDR7120_R191.Value + step_l;
                                        /*if(VTDR7120_R191.Value <= VTDR7120_R159.Value)
                                            VTDR7120_R191.Value = VTDR7120_R159.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G191.Value = VTDR7120_G191.Value - step_h;
                                        else VTDR7120_G191.Value = VTDR7120_G191.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if(VTDR7120_G191.Value <= VTDR7120_G159.Value)
                                            VTDR7120_G191.Value = VTDR7120_G159.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G191.Value = VTDR7120_G191.Value - step_l;
                                        else VTDR7120_G191.Value = VTDR7120_G191.Value + step_l;
                                        /*if(VTDR7120_G191.Value <= VTDR7120_G159.Value)
                                            VTDR7120_G191.Value = VTDR7120_G159.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B191.Value = VTDR7120_B191.Value - step_h;
                                        else VTDR7120_B191.Value = VTDR7120_B191.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if(VTDR7120_B191.Value <= VTDR7120_B159.Value)
                                            VTDR7120_B191.Value = VTDR7120_B159.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B191.Value = VTDR7120_B191.Value - step_l;
                                        else VTDR7120_B191.Value = VTDR7120_B191.Value + step_l;
                                        /*if(VTDR7120_B191.Value <= VTDR7120_B159.Value)
                                            VTDR7120_B191.Value = VTDR7120_B159.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 3:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R127.Value = VTDR7120_R127.Value - step_h;
                                        else VTDR7120_R127.Value = VTDR7120_R127.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R127.Value = VTDR7120_R127.Value - step_l;
                                        else VTDR7120_R127.Value = VTDR7120_R127.Value + step_l;
                                        /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G127.Value = VTDR7120_G127.Value - step_h;
                                        else VTDR7120_G127.Value = VTDR7120_G127.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G127.Value = VTDR7120_G127.Value - step_l;
                                        else VTDR7120_G127.Value = VTDR7120_G127.Value + step_l;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B127.Value = VTDR7120_B127.Value - step_h;
                                        else VTDR7120_B127.Value = VTDR7120_B127.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B127.Value = VTDR7120_B127.Value - step_l;
                                        else VTDR7120_B127.Value = VTDR7120_B127.Value + step_l;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 4:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R111.Value = VTDR7120_R111.Value - step_h;
                                        else VTDR7120_R111.Value = VTDR7120_R111.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R111.Value = VTDR7120_R111.Value - step_l;
                                        else VTDR7120_R111.Value = VTDR7120_R111.Value + step_l;
                                        /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G111.Value = VTDR7120_G111.Value - step_h;
                                        else VTDR7120_G111.Value = VTDR7120_G111.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G111.Value = VTDR7120_G111.Value - step_l;
                                        else VTDR7120_G111.Value = VTDR7120_G111.Value + step_l;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B111.Value = VTDR7120_B111.Value - step_h;
                                        else VTDR7120_B111.Value = VTDR7120_B111.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B111.Value = VTDR7120_B111.Value - step_l;
                                        else VTDR7120_B111.Value = VTDR7120_B111.Value + step_l;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 5:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R79.Value = VTDR7120_R79.Value - step_h;
                                        else VTDR7120_R79.Value = VTDR7120_R79.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R79.Value = VTDR7120_R79.Value - step_l;
                                        else VTDR7120_R79.Value = VTDR7120_R79.Value + step_l;
                                        /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G79.Value = VTDR7120_G79.Value - step_h;
                                        else VTDR7120_G79.Value = VTDR7120_G79.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G79.Value = VTDR7120_G79.Value - step_l;
                                        else VTDR7120_G79.Value = VTDR7120_G79.Value + step_l;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B79.Value = VTDR7120_B79.Value - step_h;
                                        else VTDR7120_B79.Value = VTDR7120_B79.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B79.Value = VTDR7120_B79.Value - step_l;
                                        else VTDR7120_B79.Value = VTDR7120_B79.Value + step_l;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 6:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R63.Value = VTDR7120_R63.Value - step_h;
                                        else VTDR7120_R63.Value = VTDR7120_R63.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R63.Value = VTDR7120_R63.Value - step_l;
                                        else VTDR7120_R63.Value = VTDR7120_R63.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G63.Value = VTDR7120_G63.Value - step_h;
                                        else VTDR7120_G63.Value = VTDR7120_G63.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G63.Value = VTDR7120_G63.Value - step_l;
                                        else VTDR7120_G63.Value = VTDR7120_G63.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B63.Value = VTDR7120_B63.Value - step_h;
                                        else VTDR7120_B63.Value = VTDR7120_B63.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B63.Value = VTDR7120_B63.Value - step_l;
                                        else VTDR7120_B63.Value = VTDR7120_B63.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 7:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R55.Value = VTDR7120_R55.Value - step_h;
                                        else VTDR7120_R55.Value = VTDR7120_R55.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R55.Value = VTDR7120_R55.Value - step_l;
                                        else VTDR7120_R55.Value = VTDR7120_R55.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G55.Value = VTDR7120_G55.Value - step_h;
                                        else VTDR7120_G55.Value = VTDR7120_G55.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G55.Value = VTDR7120_G55.Value - step_l;
                                        else VTDR7120_G55.Value = VTDR7120_G55.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B55.Value = VTDR7120_B55.Value - step_h;
                                        else VTDR7120_B55.Value = VTDR7120_B55.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B55.Value = VTDR7120_B55.Value - step_l;
                                        else VTDR7120_B55.Value = VTDR7120_B55.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 8:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R47.Value = VTDR7120_R47.Value - step_h;
                                        else VTDR7120_R47.Value = VTDR7120_R47.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R47.Value = VTDR7120_R47.Value - step_l;
                                        else VTDR7120_R47.Value = VTDR7120_R47.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G47.Value = VTDR7120_G47.Value - step_h;
                                        else VTDR7120_G47.Value = VTDR7120_G47.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G47.Value = VTDR7120_G47.Value - step_l;
                                        else VTDR7120_G47.Value = VTDR7120_G47.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B47.Value = VTDR7120_B47.Value - step_h;
                                        else VTDR7120_B47.Value = VTDR7120_B47.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B47.Value = VTDR7120_B47.Value - step_l;
                                        else VTDR7120_B47.Value = VTDR7120_B47.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 9:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R39.Value = VTDR7120_R39.Value - step_h;
                                        else VTDR7120_R39.Value = VTDR7120_R39.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R39.Value = VTDR7120_R39.Value - step_l;
                                        else VTDR7120_R39.Value = VTDR7120_R39.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G39.Value = VTDR7120_G39.Value - step_h;
                                        else VTDR7120_G39.Value = VTDR7120_G39.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G39.Value = VTDR7120_G39.Value - step_l;
                                        else VTDR7120_G39.Value = VTDR7120_G39.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B39.Value = VTDR7120_B39.Value - step_h;
                                        else VTDR7120_B39.Value = VTDR7120_B39.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B39.Value = VTDR7120_B39.Value - step_l;
                                        else VTDR7120_B39.Value = VTDR7120_B39.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 10:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R35.Value = VTDR7120_R35.Value - step_h;
                                        else VTDR7120_R35.Value = VTDR7120_R35.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R35.Value = VTDR7120_R35.Value - step_l;
                                        else VTDR7120_R35.Value = VTDR7120_R35.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G35.Value = VTDR7120_G35.Value - step_h;
                                        else VTDR7120_G35.Value = VTDR7120_G35.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G35.Value = VTDR7120_G35.Value - step_l;
                                        else VTDR7120_G35.Value = VTDR7120_G35.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B35.Value = VTDR7120_B35.Value - step_h;
                                        else VTDR7120_B35.Value = VTDR7120_B35.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B35.Value = VTDR7120_B35.Value - step_l;
                                        else VTDR7120_B35.Value = VTDR7120_B35.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 11:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R31.Value = VTDR7120_R31.Value - step_h;
                                        else VTDR7120_R31.Value = VTDR7120_R31.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R31.Value <= VTDR7120_R27.Value)
                                            VTDR7120_R31.Value = VTDR7120_R27.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R31.Value = VTDR7120_R31.Value - step_l;
                                        else VTDR7120_R31.Value = VTDR7120_R31.Value + step_l;
                                        /*if (VTDR7120_R31.Value <= VTDR7120_R27.Value)
                                            VTDR7120_R31.Value = VTDR7120_R27.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G31.Value = VTDR7120_G31.Value - step_h;
                                        else VTDR7120_G31.Value = VTDR7120_G31.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G31.Value <= VTDR7120_G27.Value)
                                            VTDR7120_G31.Value = VTDR7120_G27.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G31.Value = VTDR7120_G31.Value - step_l;
                                        else VTDR7120_G31.Value = VTDR7120_G31.Value + step_l;
                                        /*if (VTDR7120_G31.Value <= VTDR7120_G27.Value)
                                            VTDR7120_G31.Value = VTDR7120_G27.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B31.Value = VTDR7120_B31.Value - step_h;
                                        else VTDR7120_B31.Value = VTDR7120_B31.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B31.Value <= VTDR7120_B27.Value)
                                            VTDR7120_B31.Value = VTDR7120_B27.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B31.Value = VTDR7120_B31.Value - step_l;
                                        else VTDR7120_B31.Value = VTDR7120_B31.Value + step_l;
                                        /*if (VTDR7120_B31.Value <= VTDR7120_B27.Value)
                                            VTDR7120_B31.Value = VTDR7120_B27.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 12:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R11.Value = VTDR7120_R11.Value - step_h;
                                        else VTDR7120_R11.Value = VTDR7120_R11.Value + step_h;
                                        adjust_Rnum = 0;

                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R11.Value = VTDR7120_R11.Value - step_l;
                                        else VTDR7120_R11.Value = VTDR7120_R11.Value + step_l;

                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G11.Value = VTDR7120_G11.Value - step_h;
                                        else VTDR7120_G11.Value = VTDR7120_G11.Value + step_h;
                                        adjust_Gnum = 0;

                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G11.Value = VTDR7120_G11.Value - step_l;
                                        else VTDR7120_G11.Value = VTDR7120_G11.Value + step_l;

                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B11.Value = VTDR7120_B11.Value - step_h;
                                        else VTDR7120_B11.Value = VTDR7120_B11.Value + step_h;
                                        adjust_Bnum = 0;

                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B11.Value = VTDR7120_B11.Value - step_l;
                                        else VTDR7120_B11.Value = VTDR7120_B11.Value + step_l;

                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 13:
                            {
                                for (int k = 0; k < 13; k++)
                                {
                                    numPatternR.Value = Parttern_VTDR7120[k];
                                    numPatternG.Value = Parttern_VTDR7120[k];
                                    numPatternB.Value = Parttern_VTDR7120[k];
                                    OLED_Show_Click(btnPatternW, e);//写入Pattern参数
                                    Thread.Sleep(1000); //1秒=1000毫秒，
                                    Msr_CA310();
                                    CAS200_Measure_Information(auto_lum, auto_x, auto_y);
                                }
                                T17.Enabled = false;
                            }
                            break;

                        default:
                            break;
                    }
                    System.Threading.Thread.Sleep(10);
                }
                //catch
                //{
                //    T5.Enabled = false;
                //    MessageBox.Show("数值超限！");
                //    return;
                // }
            }

        }
        private void VTDR6110_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            btnBack_Click(btnBack, e);
        }
        private void btnCleanTextBox1_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
        }
        bool SerialPortFlag = true;
        private void btnInitcom_Click(object sender, EventArgs e)
        {

        }
        private void mtLoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();

                string[] arrtmp = strtmp.Split(new Char[] { ',' });

                VTDR7120_R0.Text = arrtmp[1].ToString(); VTDR7120_G0.Text = arrtmp[3].ToString(); VTDR7120_B0.Text = arrtmp[5].ToString();
                VTDR7120_R1.Text = arrtmp[7].ToString(); VTDR7120_G1.Text = arrtmp[9].ToString(); VTDR7120_B1.Text = arrtmp[11].ToString();
                VTDR7120_R3.Text = arrtmp[13].ToString(); VTDR7120_G3.Text = arrtmp[15].ToString(); VTDR7120_B3.Text = arrtmp[17].ToString();
                VTDR7120_R5.Text = arrtmp[19].ToString(); VTDR7120_G5.Text = arrtmp[21].ToString(); VTDR7120_B5.Text = arrtmp[23].ToString();
                VTDR7120_R7.Text = arrtmp[25].ToString(); VTDR7120_G7.Text = arrtmp[27].ToString(); VTDR7120_B7.Text = arrtmp[29].ToString();
                VTDR7120_R11.Text = arrtmp[31].ToString(); VTDR7120_G11.Text = arrtmp[33].ToString(); VTDR7120_B11.Text = arrtmp[35].ToString();
                VTDR7120_R15.Text = arrtmp[37].ToString(); VTDR7120_G15.Text = arrtmp[39].ToString(); VTDR7120_B15.Text = arrtmp[41].ToString();
                VTDR7120_R19.Text = arrtmp[43].ToString(); VTDR7120_G19.Text = arrtmp[45].ToString(); VTDR7120_B19.Text = arrtmp[47].ToString();
                VTDR7120_R23.Text = arrtmp[49].ToString(); VTDR7120_G23.Text = arrtmp[51].ToString(); VTDR7120_B23.Text = arrtmp[53].ToString();
                VTDR7120_R27.Text = arrtmp[55].ToString(); VTDR7120_G27.Text = arrtmp[57].ToString(); VTDR7120_B27.Text = arrtmp[59].ToString();
                VTDR7120_R31.Text = arrtmp[61].ToString(); VTDR7120_G31.Text = arrtmp[63].ToString(); VTDR7120_B31.Text = arrtmp[65].ToString();
                VTDR7120_R35.Text = arrtmp[67].ToString(); VTDR7120_G35.Text = arrtmp[69].ToString(); VTDR7120_B35.Text = arrtmp[71].ToString();
                VTDR7120_R39.Text = arrtmp[73].ToString(); VTDR7120_G39.Text = arrtmp[75].ToString(); VTDR7120_B39.Text = arrtmp[77].ToString();
                VTDR7120_R47.Text = arrtmp[79].ToString(); VTDR7120_G47.Text = arrtmp[81].ToString(); VTDR7120_B47.Text = arrtmp[83].ToString();
                VTDR7120_R55.Text = arrtmp[85].ToString(); VTDR7120_G55.Text = arrtmp[87].ToString(); VTDR7120_B55.Text = arrtmp[89].ToString();
                VTDR7120_R63.Text = arrtmp[91].ToString(); VTDR7120_G63.Text = arrtmp[93].ToString(); VTDR7120_B63.Text = arrtmp[95].ToString();
                VTDR7120_R71.Text = arrtmp[97].ToString(); VTDR7120_G71.Text = arrtmp[99].ToString(); VTDR7120_B71.Text = arrtmp[101].ToString();
                VTDR7120_R79.Text = arrtmp[103].ToString(); VTDR7120_G79.Text = arrtmp[105].ToString(); VTDR7120_B79.Text = arrtmp[107].ToString();
                VTDR7120_R95.Text = arrtmp[109].ToString(); VTDR7120_G95.Text = arrtmp[111].ToString(); VTDR7120_B95.Text = arrtmp[113].ToString();
                VTDR7120_R111.Text = arrtmp[115].ToString(); VTDR7120_G111.Text = arrtmp[117].ToString(); VTDR7120_B111.Text = arrtmp[119].ToString();
                VTDR7120_R127.Text = arrtmp[121].ToString(); VTDR7120_G127.Text = arrtmp[123].ToString(); VTDR7120_B127.Text = arrtmp[125].ToString();
                VTDR7120_R159.Text = arrtmp[127].ToString(); VTDR7120_G159.Text = arrtmp[129].ToString(); VTDR7120_B159.Text = arrtmp[131].ToString();
                VTDR7120_R191.Text = arrtmp[133].ToString(); VTDR7120_G191.Text = arrtmp[135].ToString(); VTDR7120_B191.Text = arrtmp[137].ToString();
                VTDR7120_R223.Text = arrtmp[139].ToString(); VTDR7120_G223.Text = arrtmp[141].ToString(); VTDR7120_B223.Text = arrtmp[143].ToString();
                VTDR7120_R255.Text = arrtmp[145].ToString(); VTDR7120_G255.Text = arrtmp[147].ToString(); VTDR7120_B255.Text = arrtmp[149].ToString();
            }
        }
        private void mtSaveGamma_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);

                    str = str + "R0," + VTDR7120_R0.Text + "," + "G0," + VTDR7120_G0.Text + "," + "B0," + VTDR7120_B0.Text + "\r\n";
                    str = str + "R1," + VTDR7120_R1.Text + "," + "G1," + VTDR7120_G1.Text + "," + "B1," + VTDR7120_B1.Text + "\r\n";
                    str = str + "R3," + VTDR7120_R3.Text + "," + "G3," + VTDR7120_G3.Text + "," + "B3," + VTDR7120_B3.Text + "\r\n";
                    str = str + "R5," + VTDR7120_R5.Text + "," + "G5," + VTDR7120_G5.Text + "," + "B5," + VTDR7120_B5.Text + "\r\n";
                    str = str + "R7," + VTDR7120_R7.Text + "," + "G7," + VTDR7120_G7.Text + "," + "B7," + VTDR7120_B7.Text + "\r\n";
                    str = str + "R11," + VTDR7120_R11.Text + "," + "G11," + VTDR7120_G11.Text + "," + "B11," + VTDR7120_B11.Text + "\r\n";
                    str = str + "R15," + VTDR7120_R15.Text + "," + "G15," + VTDR7120_G15.Text + "," + "B15," + VTDR7120_B15.Text + "\r\n";
                    str = str + "R19," + VTDR7120_R19.Text + "," + "G19," + VTDR7120_G19.Text + "," + "B20," + VTDR7120_B19.Text + "\r\n";
                    str = str + "R23," + VTDR7120_R23.Text + "," + "G23," + VTDR7120_G23.Text + "," + "B23," + VTDR7120_B23.Text + "\r\n";
                    str = str + "R27," + VTDR7120_R27.Text + "," + "G27," + VTDR7120_G27.Text + "," + "B27," + VTDR7120_B27.Text + "\r\n";
                    str = str + "R31," + VTDR7120_R31.Text + "," + "G31," + VTDR7120_G31.Text + "," + "B31," + VTDR7120_B31.Text + "\r\n";
                    str = str + "R35," + VTDR7120_R35.Text + "," + "G35," + VTDR7120_G35.Text + "," + "B35," + VTDR7120_B35.Text + "\r\n";
                    str = str + "R39," + VTDR7120_R39.Text + "," + "G39," + VTDR7120_G39.Text + "," + "B39," + VTDR7120_B39.Text + "\r\n";
                    str = str + "R47," + VTDR7120_R47.Text + "," + "G47," + VTDR7120_G47.Text + "," + "B47," + VTDR7120_B47.Text + "\r\n";
                    str = str + "R55," + VTDR7120_R55.Text + "," + "G55," + VTDR7120_G55.Text + "," + "B55," + VTDR7120_B55.Text + "\r\n";
                    str = str + "R63," + VTDR7120_R63.Text + "," + "G63," + VTDR7120_G63.Text + "," + "B63," + VTDR7120_B63.Text + "\r\n";
                    str = str + "R71," + VTDR7120_R71.Text + "," + "G71," + VTDR7120_G71.Text + "," + "B71," + VTDR7120_B71.Text + "\r\n";
                    str = str + "R79," + VTDR7120_R79.Text + "," + "G79," + VTDR7120_G79.Text + "," + "B79," + VTDR7120_B79.Text + "\r\n";
                    str = str + "R95," + VTDR7120_R95.Text + "," + "G95," + VTDR7120_G95.Text + "," + "B95," + VTDR7120_B95.Text + "\r\n";
                    str = str + "R111," + VTDR7120_R111.Text + "," + "G111," + VTDR7120_G111.Text + "," + "B111," + VTDR7120_B111.Text + "\r\n";
                    str = str + "R127," + VTDR7120_R127.Text + "," + "G127," + VTDR7120_G127.Text + "," + "B127," + VTDR7120_B127.Text + "\r\n";
                    str = str + "R159," + VTDR7120_R159.Text + "," + "G159," + VTDR7120_G159.Text + "," + "B159," + VTDR7120_B159.Text + "\r\n";
                    str = str + "R191," + VTDR7120_R191.Text + "," + "G191," + VTDR7120_G191.Text + "," + "B191," + VTDR7120_B191.Text + "\r\n";
                    str = str + "R223," + VTDR7120_R223.Text + "," + "G223," + VTDR7120_G223.Text + "," + "B223," + VTDR7120_B223.Text + "\r\n";
                    str = str + "R255," + VTDR7120_R255.Text + "," + "G255," + VTDR7120_G255.Text + "," + "B255," + VTDR7120_B255.Text + "\r\n";

                    sw.WriteLine(str);

                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        }
        private void btnCal_manual_MouseEnter(object sender, EventArgs e)
        {
            ToolTip p = new ToolTip();
            p.ShowAlways = true;
            p.SetToolTip(this.btnCal_manual, "CA310连接校准，自带黑画面，按下静候6秒");
        }
        private void btnBack_MouseEnter(object sender, EventArgs e)
        {
            ToolTip p = new ToolTip();
            p.ShowAlways = true;
            p.SetToolTip(this.btnBack, "返回屏体初始化设定界面");
        }
        private void groupBox131_Enter(object sender, EventArgs e)
        {

        }
        private void btnVTStop_Click(object sender, EventArgs e)
        {
            T17.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }
        private void VTDR6110_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible == true) //子窗体已开启标识
            {
                MainForm.comPort.Close();
                Thread.Sleep(5);
                MainForm.comPort.DataReceived -= new SerialDataReceivedEventHandler(MainForm.SerialPort1_DataReceived);

                Thread.Sleep(5);
                MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
                Thread.Sleep(5);
                try
                {
                    MainForm.comPort.Open();
                }
                catch (Exception)
                {
                    //MessageBox.Show("打开串口失败!!!,或其它错误。\r\n请选择正确的串口或该串口被占用", "错误提示");
                    //MainForm.this.closeSerialPort(true);
                }
                textBox1.Text += "com 已经连接！\r\n";
            }
            else
            {

            }
        }
        private void btnLocate_Demura_File_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fldb = new FolderBrowserDialog();
            fldb.ShowNewFolderButton = false;
            DialogResult res = fldb.ShowDialog();
            if (res != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("没选择任何文件.");
                return;
            }
            string path = fldb.SelectedPath;

            if (!Directory.Exists(path))
            {
                MessageBox.Show("文件夹不存在.");
                return;
            }
            listBox3_Demura_File.Items.Clear();
            string s = null;
            DirectoryInfo d = new DirectoryInfo(path);
            FileInfo[] Files = d.GetFiles("*.hex");

            // List<string> lstr = new List<string>();

            foreach (FileInfo file in Files)
            {
                s = file.Name;
                listBox3_Demura_File.Items.Add(s);
            }
            //bin文件 识别
            FileInfo[] Files1 = d.GetFiles("*.bin");
            foreach (FileInfo file in Files1)
            {
                s = file.Name;
                listBox3_Demura_File.Items.Add(s);
            }
            //bin文件 识别
            textBox5.Text = path;
        }

        //private void gamma_set_update(EventArgs e)
        //{
        //    VTDR7120_GAMMA_Click(UP_READ_GAMMA, e);
        //    System.Threading.Thread.Sleep(100);
        //    VTDR7120_GAMMA_Click(UP_GREEN_GAMMA, e);
        //    System.Threading.Thread.Sleep(100);
        //    VTDR7120_GAMMA_Click(UP_BLUE_GAMMA, e);
        //    System.Threading.Thread.Sleep(100);
        //}

        private void gamma_set_update(EventArgs e)
        {
            VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
            System.Threading.Thread.Sleep(100);
            VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
            System.Threading.Thread.Sleep(100);
            VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
            System.Threading.Thread.Sleep(100);
        }




        //25绑点gamma调节
        private void Point_25_autogamma_Click(object sender, EventArgs e)
        {
            int flag = 1;
            double Lr_d, Lg_d, Lb_d;
            int point = 24;//25绑点 1绑点不调
            //gamma_set_update(e);-----------------------??????什么作用

            D_lums = new double[24, 3];
            D_lum = new double[24];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            D_lum[0] = Convert.ToDouble(txtVT_255.Text);
            D_lum[1] = Convert.ToDouble(txtVT_223.Text);
            D_lum[2] = Convert.ToDouble(txtVT_191.Text);
            D_lum[3] = Convert.ToDouble(txtVT_159.Text);
            D_lum[4] = Convert.ToDouble(txtVT_127.Text);
            D_lum[5] = Convert.ToDouble(txtVT_111.Text);
            D_lum[6] = Convert.ToDouble(txtVT_95.Text);
            D_lum[7] = Convert.ToDouble(txtVT_79.Text);
            D_lum[8] = Convert.ToDouble(txtVT_71.Text);
            D_lum[9] = Convert.ToDouble(txtVT_63.Text);
            D_lum[10] = Convert.ToDouble(txtVT_55.Text);
            D_lum[11] = Convert.ToDouble(txtVT_47.Text);
            D_lum[12] = Convert.ToDouble(txtVT_39.Text);
            D_lum[13] = Convert.ToDouble(txtVT_35.Text);
            D_lum[14] = Convert.ToDouble(txtVT_31.Text);
            D_lum[15] = Convert.ToDouble(txtVT_27.Text);
            D_lum[16] = Convert.ToDouble(txtVT_23.Text);
            D_lum[17] = Convert.ToDouble(txtVT_19.Text);
            D_lum[18] = Convert.ToDouble(txtVT_15.Text);
            D_lum[19] = Convert.ToDouble(txtVT_11.Text);
            D_lum[20] = Convert.ToDouble(txtVT_7.Text);
            D_lum[21] = Convert.ToDouble(txtVT_5.Text);
            D_lum[22] = Convert.ToDouble(txtVT_3.Text);
            D_lum[23] = Convert.ToDouble(txtVT_1.Text);

            D_x = Convert.ToDouble(txtVT_x.Text);
            D_y = Convert.ToDouble(txtVT_y.Text);
            Lr_d = R_y * ((D_y - G_y) * (B_x - D_x) + (D_x - G_x) * (D_y - B_y)) / B_y / ((D_y - G_y) * (D_x - R_x) + (D_x - G_x) * (R_y - D_y));
            Lb_d = 1.0;
            Lg_d = G_y * ((D_y - R_y) * (B_x - D_x) + (D_x - R_x) * (D_y - B_y)) / B_y / ((D_y - R_y) * (D_x - G_x) + (D_x - R_x) * (G_y - D_y));

            for (int i = 0; i < point; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);//R
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);//G
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);//B
            }

            switch (flag)
            {
                case 1://寄存器值与亮度正比
                    {
                        lum_off = Convert.ToDouble(txtVT_loff.Text);
                        x_off = Convert.ToDouble(txtVT_xoff.Text);
                        y_off = Convert.ToDouble(txtVT_yoff.Text);

                        //VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                        //VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                        //VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);

                        if (Vesa_Check.Checked == true)
                        {
                            VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[0].ToString() + ".dsc_0001.bmp");
                        }
                        else
                        {
                            OLED_Show_Click(btnwhite, e);
                        }
                        //T17.Enabled = true;
                        Msr_CA310();
                        T18.Enabled = true;
                    }
                    break;
                case 2:   //寄存器值与亮度反比---基本没有这种IC
                    break;
                default:
                    break;
            }
        }





        //保存====原来的
        #region 
        //private void T18_Tick(object sender, EventArgs e)
        //{
        //    double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
        //    Msr_CA310();

        //    if ((auto_lum < (D_lum[index] + lum_off)) && (auto_lum > (D_lum[index] - lum_off)))//G
        //        flag1 = 0;
        //    if ((auto_y < (D_y + y_off)) && (auto_y > (D_y - y_off)) && flag1 == 0)//B
        //        flag2 = 0;
        //    if ((auto_x < (D_x + x_off)) && (auto_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
        //        flag3 = 0;
        //    if (flag1 == 0 && flag2 == 0 && flag3 == 0)
        //    {

        //        T18.Enabled = false;
        //        index++;
        //        adjust_Rnum = 0;
        //        adjust_Gnum = 0;
        //        adjust_Bnum = 0;
        //        adjust_l = 0;
        //        adjust_x = 0;
        //        adjust_y = 0;
        //        if (index == 24)
        //        {
        //            textBox1.Text = textBox1.Text + "VTDR7120 gamma调试完毕!\r\n";
        //        }
        //        if (index < 24)
        //        {
        //            switch (index)
        //            {
        //                case 0:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_255.Text) * Convert.ToDouble(textVT_223_off.Text)) / 100);
        //                    break;
        //                case 1:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_223.Text) * Convert.ToDouble(textVT_223_off.Text)) / 100);
        //                    break;
        //                case 2:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_191.Text) * Convert.ToDouble(textVT_191_off.Text)) / 100);
        //                    break;
        //                case 3:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_159.Text) * Convert.ToDouble(textVT_159_off.Text)) / 100);
        //                    break;
        //                case 4:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_127.Text) * Convert.ToDouble(textVT_127_off.Text)) / 100);
        //                    break;
        //                case 5:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_111.Text) * Convert.ToDouble(textVT_111_off.Text)) / 100);
        //                    break;
        //                case 6:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_95.Text) * Convert.ToDouble(textVT_95_off.Text)) / 100);
        //                    break;
        //                case 7:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_79.Text) * Convert.ToDouble(textVT_79_off.Text)) / 100);
        //                    break;
        //                case 8:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_71.Text) * Convert.ToDouble(textVT_71_off.Text)) / 100);
        //                    break;
        //                case 9:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_63.Text) * Convert.ToDouble(textVT_63_off.Text)) / 100);
        //                    break;
        //                case 10:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_55.Text) * Convert.ToDouble(textVT_55_off.Text)) / 100);
        //                    break;
        //                case 11:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_47.Text) * Convert.ToDouble(textVT_47_off.Text)) / 100);
        //                    break;
        //                case 12:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_39.Text) * Convert.ToDouble(textVT_39_off.Text)) / 100);
        //                    break;
        //                case 13:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_35.Text) * Convert.ToDouble(textVT_35_off.Text)) / 100);
        //                    break;
        //                case 14:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_31.Text) * Convert.ToDouble(textVT_31_off.Text)) / 100);
        //                    break;
        //                case 15:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_27.Text) * Convert.ToDouble(textVT_27_off.Text)) / 100);
        //                    break;
        //                case 16:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_23.Text) * Convert.ToDouble(textVT_23_off.Text)) / 100);
        //                    break;
        //                case 17:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_19.Text) * Convert.ToDouble(textVT_19_off.Text)) / 100);
        //                    break;
        //                case 18:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_15.Text) * Convert.ToDouble(textVT_15_off.Text)) / 100);
        //                    break;
        //                case 19:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_11.Text) * Convert.ToDouble(textVT_11_off.Text)) / 100);
        //                    break;
        //                case 20:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_7.Text) * Convert.ToDouble(textVT_7_off.Text)) / 100);
        //                    break;
        //                case 21:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_5.Text) * Convert.ToDouble(textVT_5_off.Text)) / 100);
        //                    break;
        //                case 22:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_3.Text) * Convert.ToDouble(textVT_3_off.Text)) / 100);
        //                    break;
        //                case 23:
        //                    lum_off = (double)((Convert.ToDouble(txtVT_1.Text) * Convert.ToDouble(textVT_1_off.Text)) / 100);
        //                    break;
        //                default:
        //                    break;
        //            }
        //            numPatternR.Value = Parttern_VTDR7120[index];
        //            numPatternG.Value = Parttern_VTDR7120[index];
        //            numPatternB.Value = Parttern_VTDR7120[index];

        //            if (Vesa_Check.Checked == true)//载入vesa图片
        //            {//注意一下此处的顺序
        //                switch (index)
        //                {
        //                    case 0: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[0].ToString() + ".dsc_0001.bmp"); break;
        //                    case 1: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[1].ToString() + ".dsc_0001.bmp"); break;
        //                    case 2: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[2].ToString() + ".dsc_0001.bmp"); break;
        //                    case 3: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[3].ToString() + ".dsc_0001.bmp"); break;
        //                    case 4: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[4].ToString() + ".dsc_0001.bmp"); break;
        //                    case 5: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[5].ToString() + ".dsc_0001.bmp"); break;
        //                    case 6: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[6].ToString() + ".dsc_0001.bmp"); break;
        //                    case 7: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[7].ToString() + ".dsc_0001.bmp"); break;
        //                    case 8: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[8].ToString() + ".dsc_0001.bmp"); break;
        //                    case 9: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[9].ToString() + ".dsc_0001.bmp"); break;
        //                    case 10: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[10].ToString() + ".dsc_0001.bmp"); break;
        //                    case 11: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[11].ToString() + ".dsc_0001.bmp"); break;
        //                    case 12: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[12].ToString() + ".dsc_0001.bmp"); break;
        //                    case 13: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[13].ToString() + ".dsc_0001.bmp"); break;
        //                    case 14: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[14].ToString() + ".dsc_0001.bmp"); break;
        //                    case 15: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[15].ToString() + ".dsc_0001.bmp"); break;
        //                    case 16: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[16].ToString() + ".dsc_0001.bmp"); break;
        //                    case 17: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[17].ToString() + ".dsc_0001.bmp"); break;
        //                    case 18: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[18].ToString() + ".dsc_0001.bmp"); break;
        //                    case 19: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[19].ToString() + ".dsc_0001.bmp"); break;
        //                    case 20: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[20].ToString() + ".dsc_0001.bmp"); break;
        //                    case 21: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[21].ToString() + ".dsc_0001.bmp"); break;
        //                    case 22: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[22].ToString() + ".dsc_0001.bmp"); break;
        //                    case 23: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[23].ToString() + ".dsc_0001.bmp"); break;
        //                    case 24: VTDR7120_btnPrevPic_Run("W" + Point_VTDR7120[24].ToString() + ".dsc_0001.bmp"); break;  //需要么
        //                    default:
        //                        break;
        //                }
        //            }
        //            else
        //            {
        //                OLED_Show_Click(btnPatternW, e);//写入Pattern参数
        //            }
        //            Thread.Sleep(10); //1秒=1000毫秒，
        //            T18.Enabled = true;
        //            flag1 = 1;
        //            flag2 = 1;
        //            flag3 = 1;
        //        }
        //    }
        //    else
        //    {
        //        Lr_t = R_y * ((auto_y - G_y) * (B_x - auto_x) + (auto_x - G_x) * (auto_y - B_y)) / B_y / ((auto_y - G_y) * (auto_x - R_x) + (auto_x - G_x) * (R_y - auto_y));
        //        Lb_t = 1.0;
        //        Lg_t = G_y * ((auto_y - R_y) * (B_x - auto_x) + (auto_x - R_x) * (auto_y - B_y)) / B_y / ((auto_y - R_y) * (auto_x - G_x) + (auto_x - R_x) * (G_y - auto_y));
        //        lumr = auto_lum * Lr_t / (Lr_t + Lg_t + Lb_t);
        //        lumg = auto_lum * Lg_t / (Lr_t + Lg_t + Lb_t);
        //        lumb = auto_lum * Lb_t / (Lr_t + Lg_t + Lb_t);

        //        //try
        //        {
        //            switch (index)
        //            {
        //                case 0:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R255.Value = VTDR7120_R255.Value - step_h;
        //                                else VTDR7120_R255.Value = VTDR7120_R255.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                if (VTDR7120_R255.Value >= 0x3FF)
        //                                    VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R255.Value = VTDR7120_R255.Value - step_l;
        //                                else VTDR7120_R255.Value = VTDR7120_R255.Value + step_l;
        //                                if (VTDR7120_R255.Value >= 0x3FF)
        //                                    VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G255.Value = VTDR7120_G255.Value - step_h;
        //                                else VTDR7120_G255.Value = VTDR7120_G255.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                if (VTDR7120_G255.Value >= 0x3FF)
        //                                    VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G255.Value = VTDR7120_G255.Value - step_l;
        //                                else VTDR7120_G255.Value = VTDR7120_G255.Value + step_l;
        //                                if (VTDR7120_G255.Value >= 0x3FF)
        //                                    VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B255.Value = VTDR7120_B255.Value - step_h;
        //                                else VTDR7120_B255.Value = VTDR7120_B255.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                if (VTDR7120_B255.Value >= 0x3FF)
        //                                    VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B255.Value = VTDR7120_B255.Value - step_l;
        //                                else VTDR7120_B255.Value = VTDR7120_B255.Value + step_l;
        //                                if (VTDR7120_B255.Value >= 0x3FF)
        //                                    VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;
        //                            }
        //                            adjust_Bnum++;
        //                        }

        //                        //写操作
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 1:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R223.Value = VTDR7120_R223.Value - step_h;
        //                                else VTDR7120_R223.Value = VTDR7120_R223.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R223.Value = VTDR7120_R223.Value - step_l;
        //                                else VTDR7120_R223.Value = VTDR7120_R223.Value + step_l;
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G223.Value = VTDR7120_G223.Value - step_h;
        //                                else VTDR7120_G223.Value = VTDR7120_G223.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G223.Value = VTDR7120_G223.Value - step_l;
        //                                else VTDR7120_G223.Value = VTDR7120_G223.Value + step_l;
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B223.Value = VTDR7120_B223.Value - step_h;
        //                                else VTDR7120_B223.Value = VTDR7120_B223.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B223.Value = VTDR7120_B223.Value - step_l;
        //                                else VTDR7120_B223.Value = VTDR7120_B223.Value + step_l;
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 2:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R191.Value = VTDR7120_R191.Value - step_h;
        //                                else VTDR7120_R191.Value = VTDR7120_R191.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R191.Value = VTDR7120_R191.Value - step_l;
        //                                else VTDR7120_R191.Value = VTDR7120_R191.Value + step_l;
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G191.Value = VTDR7120_G191.Value - step_h;
        //                                else VTDR7120_G191.Value = VTDR7120_G191.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G191.Value = VTDR7120_G191.Value - step_l;
        //                                else VTDR7120_G191.Value = VTDR7120_G191.Value + step_l;
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B191.Value = VTDR7120_B191.Value - step_h;
        //                                else VTDR7120_B191.Value = VTDR7120_B191.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B191.Value = VTDR7120_B191.Value - step_l;
        //                                else VTDR7120_B191.Value = VTDR7120_B191.Value + step_l;
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 3:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R159.Value = VTDR7120_R159.Value - step_h;
        //                                else VTDR7120_R159.Value = VTDR7120_R159.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if(VTDR7120_R159.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R159.Value = VTDR7120_R111.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R159.Value = VTDR7120_R159.Value - step_l;
        //                                else VTDR7120_R159.Value = VTDR7120_R159.Value + step_l;
        //                                /*if (VTDR7120_R159.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R159.Value = VTDR7120_R111.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G159.Value = VTDR7120_G159.Value - step_h;
        //                                else VTDR7120_G159.Value = VTDR7120_G159.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G159.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G159.Value = VTDR7120_G111.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G159.Value = VTDR7120_G159.Value - step_l;
        //                                else VTDR7120_G159.Value = VTDR7120_G159.Value + step_l;
        //                                /*if (VTDR7120_G159.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G159.Value = VTDR7120_G111.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B159.Value = VTDR7120_B159.Value - step_h;
        //                                else VTDR7120_B159.Value = VTDR7120_B159.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B159.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B159.Value = VTDR7120_B111.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B159.Value = VTDR7120_B159.Value - step_l;
        //                                else VTDR7120_B159.Value = VTDR7120_B159.Value + step_l;
        //                                /*if (VTDR7120_B159.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B159.Value = VTDR7120_B111.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 4:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R127.Value = VTDR7120_R127.Value - step_h;
        //                                else VTDR7120_R127.Value = VTDR7120_R127.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R127.Value = VTDR7120_R127.Value - step_l;
        //                                else VTDR7120_R127.Value = VTDR7120_R127.Value + step_l;
        //                                /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G127.Value = VTDR7120_G127.Value - step_h;
        //                                else VTDR7120_G127.Value = VTDR7120_G127.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G127.Value = VTDR7120_G127.Value - step_l;
        //                                else VTDR7120_G127.Value = VTDR7120_G127.Value + step_l;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B127.Value = VTDR7120_B127.Value - step_h;
        //                                else VTDR7120_B127.Value = VTDR7120_B127.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B127.Value = VTDR7120_B127.Value - step_l;
        //                                else VTDR7120_B127.Value = VTDR7120_B127.Value + step_l;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 5:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R111.Value = VTDR7120_R111.Value - step_h;
        //                                else VTDR7120_R111.Value = VTDR7120_R111.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R111.Value = VTDR7120_R111.Value - step_l;
        //                                else VTDR7120_R111.Value = VTDR7120_R111.Value + step_l;
        //                                /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G111.Value = VTDR7120_G111.Value - step_h;
        //                                else VTDR7120_G111.Value = VTDR7120_G111.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G111.Value = VTDR7120_G111.Value - step_l;
        //                                else VTDR7120_G111.Value = VTDR7120_G111.Value + step_l;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B111.Value = VTDR7120_B111.Value - step_h;
        //                                else VTDR7120_B111.Value = VTDR7120_B111.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B111.Value = VTDR7120_B111.Value - step_l;
        //                                else VTDR7120_B111.Value = VTDR7120_B111.Value + step_l;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 6:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R95.Value = VTDR7120_R95.Value - step_h;
        //                                else VTDR7120_R95.Value = VTDR7120_R95.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R95.Value = VTDR7120_R95.Value - step_l;
        //                                else VTDR7120_R95.Value = VTDR7120_R95.Value + step_l;
        //                                /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G95.Value = VTDR7120_G95.Value - step_h;
        //                                else VTDR7120_G95.Value = VTDR7120_G95.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G95.Value = VTDR7120_G95.Value - step_l;
        //                                else VTDR7120_G95.Value = VTDR7120_G95.Value + step_l;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B95.Value = VTDR7120_B95.Value - step_h;
        //                                else VTDR7120_B95.Value = VTDR7120_B95.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B95.Value = VTDR7120_B95.Value - step_l;
        //                                else VTDR7120_B95.Value = VTDR7120_B95.Value + step_l;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 7:
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R79.Value = VTDR7120_R79.Value - step_h;
        //                                else VTDR7120_R79.Value = VTDR7120_R79.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R79.Value = VTDR7120_R79.Value - step_l;
        //                                else VTDR7120_R79.Value = VTDR7120_R79.Value + step_l;
        //                                /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
        //                                    VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G79.Value = VTDR7120_G79.Value - step_h;
        //                                else VTDR7120_G79.Value = VTDR7120_G79.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G79.Value = VTDR7120_G79.Value - step_l;
        //                                else VTDR7120_G79.Value = VTDR7120_G79.Value + step_l;
        //                                /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
        //                                    VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B79.Value = VTDR7120_B79.Value - step_h;
        //                                else VTDR7120_B79.Value = VTDR7120_B79.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B79.Value = VTDR7120_B79.Value - step_l;
        //                                else VTDR7120_B79.Value = VTDR7120_B79.Value + step_l;
        //                                /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
        //                                    VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 8://71
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R71.Value = VTDR7120_R71.Value - step_h;
        //                                else VTDR7120_R71.Value = VTDR7120_R71.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R71.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R71.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R71.Value = VTDR7120_R71.Value - step_l;
        //                                else VTDR7120_R71.Value = VTDR7120_R71.Value + step_l;
        //                                /*if (VTDR7120_R71.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R71.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G71.Value = VTDR7120_G71.Value - step_h;
        //                                else VTDR7120_G71.Value = VTDR7120_G71.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G71.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G71.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G71.Value = VTDR7120_G71.Value - step_l;
        //                                else VTDR7120_G71.Value = VTDR7120_G71.Value + step_l;
        //                                /*if (VTDR7120_G71.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G71.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B71.Value = VTDR7120_B71.Value - step_h;
        //                                else VTDR7120_B71.Value = VTDR7120_B71.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B71.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B71.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B71.Value = VTDR7120_B71.Value - step_l;
        //                                else VTDR7120_B71.Value = VTDR7120_B71.Value + step_l;
        //                                /*if (VTDR7120_B71.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B71.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 9://63
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R63.Value = VTDR7120_R63.Value - step_h;
        //                                else VTDR7120_R63.Value = VTDR7120_R63.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R63.Value = VTDR7120_R63.Value - step_l;
        //                                else VTDR7120_R63.Value = VTDR7120_R63.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G63.Value = VTDR7120_G63.Value - step_h;
        //                                else VTDR7120_G63.Value = VTDR7120_G63.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G63.Value = VTDR7120_G63.Value - step_l;
        //                                else VTDR7120_G63.Value = VTDR7120_G63.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B63.Value = VTDR7120_B63.Value - step_h;
        //                                else VTDR7120_B63.Value = VTDR7120_B63.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B63.Value = VTDR7120_B63.Value - step_l;
        //                                else VTDR7120_B63.Value = VTDR7120_B63.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 10://55
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R55.Value = VTDR7120_R55.Value - step_h;
        //                                else VTDR7120_R55.Value = VTDR7120_R55.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R55.Value = VTDR7120_R55.Value - step_l;
        //                                else VTDR7120_R55.Value = VTDR7120_R55.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G55.Value = VTDR7120_G55.Value - step_h;
        //                                else VTDR7120_G55.Value = VTDR7120_G55.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G55.Value = VTDR7120_G55.Value - step_l;
        //                                else VTDR7120_G55.Value = VTDR7120_G55.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B55.Value = VTDR7120_B55.Value - step_h;
        //                                else VTDR7120_B55.Value = VTDR7120_B55.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B55.Value = VTDR7120_B55.Value - step_l;
        //                                else VTDR7120_B55.Value = VTDR7120_B55.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 11://47
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R47.Value = VTDR7120_R47.Value - step_h;
        //                                else VTDR7120_R47.Value = VTDR7120_R47.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R47.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R47.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R47.Value = VTDR7120_R47.Value - step_l;
        //                                else VTDR7120_R47.Value = VTDR7120_R47.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R47.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R47.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G47.Value = VTDR7120_G47.Value - step_h;
        //                                else VTDR7120_G47.Value = VTDR7120_G47.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G47.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G47.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G47.Value = VTDR7120_G47.Value - step_l;
        //                                else VTDR7120_G47.Value = VTDR7120_G47.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G47.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G47.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B47.Value = VTDR7120_B47.Value - step_h;
        //                                else VTDR7120_B47.Value = VTDR7120_B47.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B47.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B47.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B47.Value = VTDR7120_B47.Value - step_l;
        //                                else VTDR7120_B47.Value = VTDR7120_B47.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B47.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B47.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 12://39
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R39.Value = VTDR7120_R39.Value - step_h;
        //                                else VTDR7120_R39.Value = VTDR7120_R39.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R39.Value = VTDR7120_R39.Value - step_l;
        //                                else VTDR7120_R39.Value = VTDR7120_R39.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G39.Value = VTDR7120_G39.Value - step_h;
        //                                else VTDR7120_G39.Value = VTDR7120_G39.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G39.Value = VTDR7120_G39.Value - step_l;
        //                                else VTDR7120_G39.Value = VTDR7120_G39.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B39.Value = VTDR7120_B39.Value - step_h;
        //                                else VTDR7120_B39.Value = VTDR7120_B39.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B39.Value = VTDR7120_B39.Value - step_l;
        //                                else VTDR7120_B39.Value = VTDR7120_B39.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 13://35
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R35.Value = VTDR7120_R35.Value - step_h;
        //                                else VTDR7120_R35.Value = VTDR7120_R35.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R35.Value = VTDR7120_R35.Value - step_l;
        //                                else VTDR7120_R35.Value = VTDR7120_R35.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G35.Value = VTDR7120_G35.Value - step_h;
        //                                else VTDR7120_G35.Value = VTDR7120_G35.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G35.Value = VTDR7120_G35.Value - step_l;
        //                                else VTDR7120_G35.Value = VTDR7120_G35.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B35.Value = VTDR7120_B35.Value - step_h;
        //                                else VTDR7120_B35.Value = VTDR7120_B35.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B35.Value = VTDR7120_B35.Value - step_l;
        //                                else VTDR7120_B35.Value = VTDR7120_B35.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 14://31
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R31.Value = VTDR7120_R31.Value - step_h;
        //                                else VTDR7120_R31.Value = VTDR7120_R31.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R31.Value = VTDR7120_R31.Value - step_l;
        //                                else VTDR7120_R31.Value = VTDR7120_R31.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G31.Value = VTDR7120_G31.Value - step_h;
        //                                else VTDR7120_G31.Value = VTDR7120_G31.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G31.Value = VTDR7120_G31.Value - step_l;
        //                                else VTDR7120_G31.Value = VTDR7120_G31.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B31.Value = VTDR7120_B31.Value - step_h;
        //                                else VTDR7120_B31.Value = VTDR7120_B31.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B31.Value = VTDR7120_B31.Value - step_l;
        //                                else VTDR7120_B31.Value = VTDR7120_B31.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 15://27
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R27.Value = VTDR7120_R27.Value - step_h;
        //                                else VTDR7120_R27.Value = VTDR7120_R27.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R27.Value = VTDR7120_R27.Value - step_l;
        //                                else VTDR7120_R27.Value = VTDR7120_R27.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G27.Value = VTDR7120_G27.Value - step_h;
        //                                else VTDR7120_G27.Value = VTDR7120_G27.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G27.Value = VTDR7120_G27.Value - step_l;
        //                                else VTDR7120_G27.Value = VTDR7120_G27.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B27.Value = VTDR7120_B27.Value - step_h;
        //                                else VTDR7120_B27.Value = VTDR7120_B27.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B27.Value = VTDR7120_B27.Value - step_l;
        //                                else VTDR7120_B27.Value = VTDR7120_B27.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 16://23
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R23.Value = VTDR7120_R23.Value - step_h;
        //                                else VTDR7120_R23.Value = VTDR7120_R23.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R23.Value = VTDR7120_R23.Value - step_l;
        //                                else VTDR7120_R23.Value = VTDR7120_R23.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G23.Value = VTDR7120_G23.Value - step_h;
        //                                else VTDR7120_G23.Value = VTDR7120_G23.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G23.Value = VTDR7120_G23.Value - step_l;
        //                                else VTDR7120_G23.Value = VTDR7120_G23.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B23.Value = VTDR7120_B23.Value - step_h;
        //                                else VTDR7120_B23.Value = VTDR7120_B23.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B23.Value = VTDR7120_B23.Value - step_l;
        //                                else VTDR7120_B23.Value = VTDR7120_B23.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 17://19
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R19.Value = VTDR7120_R19.Value - step_h;
        //                                else VTDR7120_R19.Value = VTDR7120_R19.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R19.Value = VTDR7120_R19.Value - step_l;
        //                                else VTDR7120_R19.Value = VTDR7120_R19.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G19.Value = VTDR7120_G19.Value - step_h;
        //                                else VTDR7120_G19.Value = VTDR7120_G19.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G19.Value = VTDR7120_G19.Value - step_l;
        //                                else VTDR7120_G19.Value = VTDR7120_G19.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B19.Value = VTDR7120_B19.Value - step_h;
        //                                else VTDR7120_B19.Value = VTDR7120_B19.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B19.Value = VTDR7120_B19.Value - step_l;
        //                                else VTDR7120_B19.Value = VTDR7120_B19.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 18://15
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R15.Value = VTDR7120_R15.Value - step_h;
        //                                else VTDR7120_R15.Value = VTDR7120_R15.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R15.Value = VTDR7120_R15.Value - step_l;
        //                                else VTDR7120_R15.Value = VTDR7120_R15.Value + step_l;
        //                                /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
        //                                    VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G15.Value = VTDR7120_G15.Value - step_h;
        //                                else VTDR7120_G15.Value = VTDR7120_G15.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G15.Value = VTDR7120_G15.Value - step_l;
        //                                else VTDR7120_G15.Value = VTDR7120_G15.Value + step_l;
        //                                /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
        //                                    VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B15.Value = VTDR7120_B15.Value - step_h;
        //                                else VTDR7120_B15.Value = VTDR7120_B15.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B15.Value = VTDR7120_B15.Value - step_l;
        //                                else VTDR7120_B15.Value = VTDR7120_B15.Value + step_l;
        //                                /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
        //                                    VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 19://11
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R11.Value = VTDR7120_R11.Value - step_h;
        //                                else VTDR7120_R11.Value = VTDR7120_R11.Value + step_h;
        //                                adjust_Rnum = 0;
        //                                /*if (VTDR7120_R11.Value <= VTDR7120_R27.Value)
        //                                    VTDR7120_R11.Value = VTDR7120_R27.Value + step_h;*/
        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R11.Value = VTDR7120_R11.Value - step_l;
        //                                else VTDR7120_R11.Value = VTDR7120_R11.Value + step_l;
        //                                /*if (VTDR7120_R11.Value <= VTDR7120_R27.Value)
        //                                    VTDR7120_R11.Value = VTDR7120_R27.Value + step_h;*/
        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G11.Value = VTDR7120_G11.Value - step_h;
        //                                else VTDR7120_G11.Value = VTDR7120_G11.Value + step_h;
        //                                adjust_Gnum = 0;
        //                                /*if (VTDR7120_G11.Value <= VTDR7120_G27.Value)
        //                                    VTDR7120_G11.Value = VTDR7120_G27.Value + step_h;*/
        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G11.Value = VTDR7120_G11.Value - step_l;
        //                                else VTDR7120_G11.Value = VTDR7120_G11.Value + step_l;
        //                                /*if (VTDR7120_G11.Value <= VTDR7120_G27.Value)
        //                                    VTDR7120_G11.Value = VTDR7120_G27.Value + step_h;*/
        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B11.Value = VTDR7120_B11.Value - step_h;
        //                                else VTDR7120_B11.Value = VTDR7120_B11.Value + step_h;
        //                                adjust_Bnum = 0;
        //                                /*if (VTDR7120_B11.Value <= VTDR7120_B27.Value)
        //                                    VTDR7120_B11.Value = VTDR7120_B27.Value + step_h;*/
        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B11.Value = VTDR7120_B11.Value - step_l;
        //                                else VTDR7120_B11.Value = VTDR7120_B11.Value + step_l;
        //                                /*if (VTDR7120_B11.Value <= VTDR7120_B27.Value)
        //                                    VTDR7120_B11.Value = VTDR7120_B27.Value + step_h;*/
        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 20://7
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R7.Value = VTDR7120_R7.Value - step_h;
        //                                else VTDR7120_R7.Value = VTDR7120_R7.Value + step_h;
        //                                adjust_Rnum = 0;

        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R7.Value = VTDR7120_R7.Value - step_l;
        //                                else VTDR7120_R7.Value = VTDR7120_R7.Value + step_l;

        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G7.Value = VTDR7120_G7.Value - step_h;
        //                                else VTDR7120_G7.Value = VTDR7120_G7.Value + step_h;
        //                                adjust_Gnum = 0;

        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G7.Value = VTDR7120_G7.Value - step_l;
        //                                else VTDR7120_G7.Value = VTDR7120_G7.Value + step_l;

        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B7.Value = VTDR7120_B7.Value - step_h;
        //                                else VTDR7120_B7.Value = VTDR7120_B7.Value + step_h;
        //                                adjust_Bnum = 0;

        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B7.Value = VTDR7120_B7.Value - step_l;
        //                                else VTDR7120_B7.Value = VTDR7120_B7.Value + step_l;

        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 21://5
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R5.Value = VTDR7120_R5.Value - step_h;
        //                                else VTDR7120_R5.Value = VTDR7120_R5.Value + step_h;
        //                                adjust_Rnum = 0;

        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R5.Value = VTDR7120_R5.Value - step_l;
        //                                else VTDR7120_R5.Value = VTDR7120_R5.Value + step_l;

        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G5.Value = VTDR7120_G5.Value - step_h;
        //                                else VTDR7120_G5.Value = VTDR7120_G5.Value + step_h;
        //                                adjust_Gnum = 0;

        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G5.Value = VTDR7120_G5.Value - step_l;
        //                                else VTDR7120_G5.Value = VTDR7120_G5.Value + step_l;

        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B5.Value = VTDR7120_B5.Value - step_h;
        //                                else VTDR7120_B5.Value = VTDR7120_B5.Value + step_h;
        //                                adjust_Bnum = 0;

        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B5.Value = VTDR7120_B5.Value - step_l;
        //                                else VTDR7120_B5.Value = VTDR7120_B5.Value + step_l;

        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 22://3
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R3.Value = VTDR7120_R3.Value - step_h;
        //                                else VTDR7120_R3.Value = VTDR7120_R3.Value + step_h;
        //                                adjust_Rnum = 0;

        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R3.Value = VTDR7120_R3.Value - step_l;
        //                                else VTDR7120_R3.Value = VTDR7120_R3.Value + step_l;

        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G3.Value = VTDR7120_G3.Value - step_h;
        //                                else VTDR7120_G3.Value = VTDR7120_G3.Value + step_h;
        //                                adjust_Gnum = 0;

        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G3.Value = VTDR7120_G3.Value - step_l;
        //                                else VTDR7120_G3.Value = VTDR7120_G3.Value + step_l;

        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B3.Value = VTDR7120_B3.Value - step_h;
        //                                else VTDR7120_B3.Value = VTDR7120_B3.Value + step_h;
        //                                adjust_Bnum = 0;

        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B3.Value = VTDR7120_B3.Value - step_l;
        //                                else VTDR7120_B3.Value = VTDR7120_B3.Value + step_l;

        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;
        //                case 23://1
        //                    {
        //                        if (flag3 == 1)
        //                        {
        //                            if (adjust_Rnum > 10)
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R1.Value = VTDR7120_R1.Value - step_h;
        //                                else VTDR7120_R1.Value = VTDR7120_R1.Value + step_h;
        //                                adjust_Rnum = 0;

        //                                adjust_x++;
        //                                if (adjust_x > 50)
        //                                {
        //                                    x_off += 0.0005;
        //                                    adjust_x = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumr > D_lums[index, 0])
        //                                    VTDR7120_R1.Value = VTDR7120_R1.Value - step_l;
        //                                else VTDR7120_R1.Value = VTDR7120_R1.Value + step_l;

        //                            }
        //                            adjust_Rnum++;
        //                        }
        //                        if (flag1 == 1)
        //                        {
        //                            if (adjust_Gnum > 10)
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G1.Value = VTDR7120_G1.Value - step_h;
        //                                else VTDR7120_G1.Value = VTDR7120_G1.Value + step_h;
        //                                adjust_Gnum = 0;

        //                                adjust_l++;
        //                                if (adjust_l > 50)
        //                                {
        //                                    lum_off *= 1.5;
        //                                    adjust_l = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumg > D_lums[index, 1])
        //                                    VTDR7120_G1.Value = VTDR7120_G1.Value - step_l;
        //                                else VTDR7120_G1.Value = VTDR7120_G1.Value + step_l;

        //                            }
        //                            adjust_Gnum++;
        //                        }
        //                        if (flag2 == 1)
        //                        {
        //                            if (adjust_Bnum > 10)
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B1.Value = VTDR7120_B1.Value - step_h;
        //                                else VTDR7120_B1.Value = VTDR7120_B1.Value + step_h;
        //                                adjust_Bnum = 0;

        //                                adjust_y++;
        //                                if (adjust_y > 50)
        //                                {
        //                                    y_off += 0.0005;
        //                                    adjust_y = 0;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                if (lumb > D_lums[index, 2])
        //                                    VTDR7120_B1.Value = VTDR7120_B1.Value - step_l;
        //                                else VTDR7120_B1.Value = VTDR7120_B1.Value + step_l;

        //                            }
        //                            adjust_Bnum++;
        //                        }
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
        //                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
        //                        //Thread.Sleep(100);
        //                    }
        //                    break;

        //                default:
        //                    break;
        //            }
        //            System.Threading.Thread.Sleep(10);
        //        }
        //        //catch
        //        //{
        //        //    T5.Enabled = false;
        //        //    MessageBox.Show("数值超限！");
        //        //    return;
        //        // }
        //    }

        //}
        #endregion
        bool gammasetjumpflag = false;
        private void gammasetjump_Click(object sender, EventArgs e)
        {
            gammasetjumpflag = true;
        }

        //修改
        private void T18_Tick(object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
            Msr_CA310();

            if ((auto_lum < (D_lum[index] + lum_off)) && (auto_lum > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((auto_y < (D_y + y_off)) && (auto_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((auto_x < (D_x + x_off)) && (auto_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;
            if ((flag1 == 0 && flag2 == 0 && flag3 == 0) | gammasetjumpflag)
            {
                gammasetjumpflag = false;
                T18.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index == 24)
                {
                    textBox1.Text = textBox1.Text + "VTDR7120 gamma调试完毕!\r\n";
                }
                if (index < 24)
                {
                    switch (index)
                    {
                        case 0:
                            lum_off = (Convert.ToDouble(txtVT_255.Text) * Convert.ToDouble(textVT_223_off.Text)) / 200;
                            break;
                        case 1:
                            lum_off = (Convert.ToDouble(txtVT_223.Text) * Convert.ToDouble(textVT_223_off.Text)) / 200;
                            break;
                        case 2:
                            lum_off = (Convert.ToDouble(txtVT_191.Text) * Convert.ToDouble(textVT_191_off.Text)) / 100;
                            break;
                        case 3:
                            lum_off = (Convert.ToDouble(txtVT_159.Text) * Convert.ToDouble(textVT_159_off.Text)) / 100;
                            break;
                        case 4:
                            lum_off = (Convert.ToDouble(txtVT_127.Text) * Convert.ToDouble(textVT_127_off.Text)) / 100;
                            break;
                        case 5:
                            lum_off = (Convert.ToDouble(txtVT_111.Text) * Convert.ToDouble(textVT_111_off.Text)) / 100;
                            break;
                        case 6:
                            lum_off = (Convert.ToDouble(txtVT_95.Text) * Convert.ToDouble(textVT_95_off.Text)) / 100;
                            break;
                        case 7:
                            lum_off = (Convert.ToDouble(txtVT_79.Text) * Convert.ToDouble(textVT_79_off.Text)) / 100;
                            break;
                        case 8:
                            lum_off = (Convert.ToDouble(txtVT_71.Text) * Convert.ToDouble(textVT_71_off.Text)) / 100;
                            break;
                        case 9:
                            lum_off = (Convert.ToDouble(txtVT_63.Text) * Convert.ToDouble(textVT_63_off.Text)) / 100;
                            break;
                        case 10:
                            lum_off = (Convert.ToDouble(txtVT_55.Text) * Convert.ToDouble(textVT_55_off.Text)) / 100;
                            break;
                        case 11:
                            lum_off = (Convert.ToDouble(txtVT_47.Text) * Convert.ToDouble(textVT_47_off.Text)) / 100;
                            break;
                        case 12:
                            lum_off = (Convert.ToDouble(txtVT_39.Text) * Convert.ToDouble(textVT_39_off.Text)) / 100;
                            break;
                        case 13:
                            lum_off = (Convert.ToDouble(txtVT_35.Text) * Convert.ToDouble(textVT_35_off.Text)) / 100;
                            break;
                        case 14:
                            lum_off = (Convert.ToDouble(txtVT_31.Text) * Convert.ToDouble(textVT_31_off.Text)) / 100;
                            break;
                        case 15:
                            lum_off = (Convert.ToDouble(txtVT_27.Text) * Convert.ToDouble(textVT_27_off.Text)) / 100;
                            break;
                        case 16:
                            lum_off = (Convert.ToDouble(txtVT_23.Text) * Convert.ToDouble(textVT_23_off.Text)) / 100;
                            break;
                        case 17:
                            lum_off = (Convert.ToDouble(txtVT_19.Text) * Convert.ToDouble(textVT_19_off.Text)) / 100;
                            break;
                        case 18:
                            lum_off = (Convert.ToDouble(txtVT_15.Text) * Convert.ToDouble(textVT_15_off.Text)) / 100;
                            break;
                        case 19:
                            lum_off = (Convert.ToDouble(txtVT_11.Text) * Convert.ToDouble(textVT_11_off.Text)) / 100;
                            break;
                        case 20:
                            lum_off = (Convert.ToDouble(txtVT_7.Text) * Convert.ToDouble(textVT_7_off.Text)) / 100;
                            break;
                        case 21:
                            lum_off = (Convert.ToDouble(txtVT_5.Text) * Convert.ToDouble(textVT_5_off.Text)) / 100;
                            break;
                        case 22:
                            lum_off = (Convert.ToDouble(txtVT_3.Text) * Convert.ToDouble(textVT_3_off.Text)) / 100;
                            break;
                        case 23:
                            lum_off = (Convert.ToDouble(txtVT_1.Text) * Convert.ToDouble(textVT_1_off.Text)) / 100;
                            break;
                        default:
                            break;
                    }
                    numPatternR.Value = Parttern_VTDR7120[index];
                    numPatternG.Value = Parttern_VTDR7120[index];
                    numPatternB.Value = Parttern_VTDR7120[index];

                    if (Vesa_Check.Checked == true)//载入vesa图片
                    {
                        VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[index].ToString() + ".dsc_0001.bmp");
                        // VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[0].ToString() + ".dsc_0001.bmp");
                        //switch (index)
                        //{
                        //    case 0: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[0].ToString() + ".dsc_0001.bmp"); break;
                        //    case 1: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[1].ToString() + ".dsc_0001.bmp"); break;
                        //    case 2: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[2].ToString() + ".dsc_0001.bmp"); break;
                        //    case 3: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[3].ToString() + ".dsc_0001.bmp"); break;
                        //    case 4: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[4].ToString() + ".dsc_0001.bmp"); break;
                        //    case 5: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[5].ToString() + ".dsc_0001.bmp"); break;
                        //    case 6: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[6].ToString() + ".dsc_0001.bmp"); break;
                        //    case 7: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[7].ToString() + ".dsc_0001.bmp"); break;
                        //    case 8: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[8].ToString() + ".dsc_0001.bmp"); break;
                        //    case 9: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[9].ToString() + ".dsc_0001.bmp"); break;
                        //    case 10: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[10].ToString() + ".dsc_0001.bmp"); break;
                        //    case 11: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[11].ToString() + ".dsc_0001.bmp"); break;
                        //    case 12: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[12].ToString() + ".dsc_0001.bmp"); break;
                        //    case 13: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[13].ToString() + ".dsc_0001.bmp"); break;
                        //    case 14: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[14].ToString() + ".dsc_0001.bmp"); break;
                        //    case 15: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[15].ToString() + ".dsc_0001.bmp"); break;
                        //    case 16: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[16].ToString() + ".dsc_0001.bmp"); break;
                        //    case 17: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[17].ToString() + ".dsc_0001.bmp"); break;
                        //    case 18: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[18].ToString() + ".dsc_0001.bmp"); break;
                        //    case 19: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[19].ToString() + ".dsc_0001.bmp"); break;
                        //    case 20: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[20].ToString() + ".dsc_0001.bmp"); break;
                        //    case 21: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[21].ToString() + ".dsc_0001.bmp"); break;
                        //    case 22: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[22].ToString() + ".dsc_0001.bmp"); break;
                        //    case 23: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[23].ToString() + ".dsc_0001.bmp"); break;
                        //    case 24: VTDR7120_btnPrevPic_Run("A" + Point_VTDR7120[24].ToString() + ".dsc_0001.bmp"); break;  //需要么
                        //    default:
                        //        break;
                        //}


                    }
                    else
                    {
                        OLED_Show_Click(btnPatternW, e);//写入Pattern参数
                    }
                    Thread.Sleep(10); //1秒=1000毫秒，
                    T18.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                Lr_t = R_y * ((auto_y - G_y) * (B_x - auto_x) + (auto_x - G_x) * (auto_y - B_y)) / B_y / ((auto_y - G_y) * (auto_x - R_x) + (auto_x - G_x) * (R_y - auto_y));
                Lb_t = 1.0;
                Lg_t = G_y * ((auto_y - R_y) * (B_x - auto_x) + (auto_x - R_x) * (auto_y - B_y)) / B_y / ((auto_y - R_y) * (auto_x - G_x) + (auto_x - R_x) * (G_y - auto_y));
                lumr = auto_lum * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = auto_lum * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = auto_lum * Lb_t / (Lr_t + Lg_t + Lb_t);

                try
                {
                    switch (index)
                    {
                        case 0:
                            {

                                if (flag1 == 1)  //G
                                {
                                    if (adjust_Gnum > 15)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G255.Value = VTDR7120_G255.Value - step_h;
                                        else VTDR7120_G255.Value = VTDR7120_G255.Value + step_h;
                                        if (VTDR7120_G255.Value >= 0x3FF)
                                            //VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;
                                            VTDR7120_G255.Value = 0x3FF - step_h;
                                        adjust_Gnum = 0;
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G255.Value = VTDR7120_G255.Value - step_l;
                                        else VTDR7120_G255.Value = VTDR7120_G255.Value + step_l;
                                        //if (VTDR7120_G255.Value >= 0x3FF)
                                        //    VTDR7120_G255.Value = VTDR7120_G223.Value + step_h;
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 15)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R255.Value = VTDR7120_R255.Value - step_h;
                                        else VTDR7120_R255.Value = VTDR7120_R255.Value + step_h;
                                        if (VTDR7120_R255.Value >= 0x3FF)
                                            //VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;
                                            VTDR7120_R255.Value = 0x3FF - step_h;
                                        adjust_Rnum = 0;
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R255.Value = VTDR7120_R255.Value - step_l;
                                        else VTDR7120_R255.Value = VTDR7120_R255.Value + step_l;
                                        //if (VTDR7120_R255.Value >= 0x3FF)
                                        //    VTDR7120_R255.Value = VTDR7120_R223.Value + step_h;
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 15)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B255.Value = VTDR7120_B255.Value - step_h;
                                        else VTDR7120_B255.Value = VTDR7120_B255.Value + step_h;
                                        if (VTDR7120_B255.Value >= 0x3FF)
                                            //  VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;
                                            VTDR7120_B255.Value = 0x3FF - step_h;
                                        adjust_Bnum = 0;
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B255.Value = VTDR7120_B255.Value - step_l;
                                        else VTDR7120_B255.Value = VTDR7120_B255.Value + step_l;
                                        if (VTDR7120_B255.Value >= 0x3FF)
                                            VTDR7120_B255.Value = VTDR7120_B223.Value + step_h;
                                    }
                                    adjust_Bnum++;
                                }

                                //写操作
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 1:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 15)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R223.Value = VTDR7120_R223.Value - step_h;
                                        else VTDR7120_R223.Value = VTDR7120_R223.Value + step_h;
                                        if (VTDR7120_R223.Value >= VTDR7120_R255.Value)
                                            VTDR7120_R223.Value = VTDR7120_R255.Value - 0xFF;
                                        adjust_Rnum = 0;
                                        adjust_x++;
                                        if (VTDR7120_R223.Value >= VTDR7120_R255.Value)
                                            VTDR7120_R223.Value = VTDR7120_R255.Value - 0xff;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R223.Value = VTDR7120_R223.Value - step_l;
                                        else VTDR7120_R223.Value = VTDR7120_R223.Value + step_l;
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 15)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G223.Value = VTDR7120_G223.Value - step_h;
                                        else VTDR7120_G223.Value = VTDR7120_G223.Value + step_h;
                                        if (VTDR7120_G223.Value >= VTDR7120_G255.Value)
                                            VTDR7120_G223.Value = VTDR7120_G255.Value - 0xFF;
                                        adjust_Gnum = 0;
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G223.Value = VTDR7120_G223.Value - step_l;
                                        else VTDR7120_G223.Value = VTDR7120_G223.Value + step_l;
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 15)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B223.Value = VTDR7120_B223.Value - step_h;
                                        else VTDR7120_B223.Value = VTDR7120_B223.Value + step_h;
                                        if (VTDR7120_B223.Value >= VTDR7120_B255.Value)
                                            VTDR7120_B223.Value = VTDR7120_B255.Value - 0xFF;
                                        adjust_Bnum = 0;
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B223.Value = VTDR7120_B223.Value - step_l;
                                        else VTDR7120_B223.Value = VTDR7120_B223.Value + step_l;
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 2:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 15)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R191.Value = VTDR7120_R191.Value - step_h;
                                        else VTDR7120_R191.Value = VTDR7120_R191.Value + step_h;
                                        if (VTDR7120_R191.Value >= VTDR7120_R223.Value)
                                            VTDR7120_R191.Value = VTDR7120_R223.Value - 0xFF;
                                        adjust_Rnum = 0;
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R191.Value = VTDR7120_R191.Value - step_l;
                                        else VTDR7120_R191.Value = VTDR7120_R191.Value + step_l;
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 15)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G191.Value = VTDR7120_G191.Value - step_h;
                                        else VTDR7120_G191.Value = VTDR7120_G191.Value + step_h;
                                        if (VTDR7120_G191.Value >= VTDR7120_G223.Value)
                                            VTDR7120_G191.Value = VTDR7120_G223.Value - 0xFF;
                                        adjust_Gnum = 0;
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G191.Value = VTDR7120_G191.Value - step_l;
                                        else VTDR7120_G191.Value = VTDR7120_G191.Value + step_l;
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 15)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B191.Value = VTDR7120_B191.Value - step_h;
                                        else VTDR7120_B191.Value = VTDR7120_B191.Value + step_h;
                                        if (VTDR7120_B191.Value >= VTDR7120_B223.Value)
                                            VTDR7120_B191.Value = VTDR7120_B223.Value - 0xFF;
                                        adjust_Bnum = 0;
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B191.Value = VTDR7120_B191.Value - step_l;
                                        else VTDR7120_B191.Value = VTDR7120_B191.Value + step_l;
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 3:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 15)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R159.Value = VTDR7120_R159.Value - step_h;
                                        else VTDR7120_R159.Value = VTDR7120_R159.Value + step_h;
                                        adjust_Rnum = 0;

                                        adjust_x++;

                                        if (VTDR7120_R159.Value >= VTDR7120_R191.Value)
                                            VTDR7120_R159.Value = VTDR7120_R191.Value - 0xFF;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R159.Value = VTDR7120_R159.Value - step_l;
                                        else VTDR7120_R159.Value = VTDR7120_R159.Value + step_l;
                                        /*if (VTDR7120_R159.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R159.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 15)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G159.Value = VTDR7120_G159.Value - step_h;
                                        else VTDR7120_G159.Value = VTDR7120_G159.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G159.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G159.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (VTDR7120_G159.Value >= VTDR7120_G191.Value)
                                            VTDR7120_G159.Value = VTDR7120_G191.Value - 0xFF;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G159.Value = VTDR7120_G159.Value - step_l;
                                        else VTDR7120_G159.Value = VTDR7120_G159.Value + step_l;
                                        /*if (VTDR7120_G159.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G159.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 15)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B159.Value = VTDR7120_B159.Value - step_h;
                                        else VTDR7120_B159.Value = VTDR7120_B159.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B159.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B159.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (VTDR7120_B159.Value >= VTDR7120_B191.Value)
                                            VTDR7120_B159.Value = VTDR7120_B191.Value - 0xFF;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B159.Value = VTDR7120_B159.Value - step_l;
                                        else VTDR7120_B159.Value = VTDR7120_B159.Value + step_l;
                                        /*if (VTDR7120_B159.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B159.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        //=======================================
                        //================if (VTDR7120_R159.Value >= VTDR7120_R191.Value)
                        // ================ VTDR7120_R159.Value = VTDR7120_R191.Value - 0xFF;
                        case 4:
                            {
                                if (VTDR7120_R127.Value >= VTDR7120_R159.Value)
                                    VTDR7120_R127.Value = VTDR7120_R159.Value - 0xFF;
                                if (VTDR7120_G127.Value >= VTDR7120_G159.Value)
                                    VTDR7120_G127.Value = VTDR7120_G159.Value - 0xFF;
                                if (VTDR7120_B127.Value >= VTDR7120_B191.Value)
                                    VTDR7120_B127.Value = VTDR7120_B159.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R127.Value = VTDR7120_R127.Value - step_h;
                                        else VTDR7120_R127.Value = VTDR7120_R127.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R127.Value = VTDR7120_R127.Value - step_l;
                                        else VTDR7120_R127.Value = VTDR7120_R127.Value + step_l;
                                        /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G127.Value = VTDR7120_G127.Value - step_h;
                                        else VTDR7120_G127.Value = VTDR7120_G127.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G127.Value = VTDR7120_G127.Value - step_l;
                                        else VTDR7120_G127.Value = VTDR7120_G127.Value + step_l;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B127.Value = VTDR7120_B127.Value - step_h;
                                        else VTDR7120_B127.Value = VTDR7120_B127.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B127.Value = VTDR7120_B127.Value - step_l;
                                        else VTDR7120_B127.Value = VTDR7120_B127.Value + step_l;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 5:
                            {

                                if (VTDR7120_R111.Value >= VTDR7120_R127.Value)
                                    VTDR7120_R111.Value = VTDR7120_R127.Value - 0xFF;
                                if (VTDR7120_G111.Value >= VTDR7120_G127.Value)
                                    VTDR7120_G111.Value = VTDR7120_G127.Value - 0xFF;
                                if (VTDR7120_B111.Value >= VTDR7120_B127.Value)
                                    VTDR7120_B111.Value = VTDR7120_B127.Value - 0xFF;


                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R111.Value = VTDR7120_R111.Value - step_h;
                                        else VTDR7120_R111.Value = VTDR7120_R111.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R111.Value = VTDR7120_R111.Value - step_l;
                                        else VTDR7120_R111.Value = VTDR7120_R111.Value + step_l;
                                        /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G111.Value = VTDR7120_G111.Value - step_h;
                                        else VTDR7120_G111.Value = VTDR7120_G111.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G111.Value = VTDR7120_G111.Value - step_l;
                                        else VTDR7120_G111.Value = VTDR7120_G111.Value + step_l;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B111.Value = VTDR7120_B111.Value - step_h;
                                        else VTDR7120_B111.Value = VTDR7120_B111.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B111.Value = VTDR7120_B111.Value - step_l;
                                        else VTDR7120_B111.Value = VTDR7120_B111.Value + step_l;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 6:
                            {
                                if (VTDR7120_R95.Value >= VTDR7120_R111.Value)
                                    VTDR7120_R95.Value = VTDR7120_R111.Value - 0xFF;
                                if (VTDR7120_G95.Value >= VTDR7120_G111.Value)
                                    VTDR7120_G95.Value = VTDR7120_G111.Value - 0xFF;
                                if (VTDR7120_B95.Value >= VTDR7120_B111.Value)
                                    VTDR7120_B95.Value = VTDR7120_B111.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R95.Value = VTDR7120_R95.Value - step_h;
                                        else VTDR7120_R95.Value = VTDR7120_R95.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R95.Value = VTDR7120_R95.Value - step_l;
                                        else VTDR7120_R95.Value = VTDR7120_R95.Value + step_l;
                                        /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G95.Value = VTDR7120_G95.Value - step_h;
                                        else VTDR7120_G95.Value = VTDR7120_G95.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G95.Value = VTDR7120_G95.Value - step_l;
                                        else VTDR7120_G95.Value = VTDR7120_G95.Value + step_l;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B95.Value = VTDR7120_B95.Value - step_h;
                                        else VTDR7120_B95.Value = VTDR7120_B95.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B95.Value = VTDR7120_B95.Value - step_l;
                                        else VTDR7120_B95.Value = VTDR7120_B95.Value + step_l;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 7:
                            {
                                if (VTDR7120_R79.Value >= VTDR7120_R95.Value)
                                    VTDR7120_R79.Value = VTDR7120_R95.Value - 0xFF;
                                if (VTDR7120_G79.Value >= VTDR7120_G95.Value)
                                    VTDR7120_G79.Value = VTDR7120_G95.Value - 0xFF;
                                if (VTDR7120_B79.Value >= VTDR7120_B95.Value)
                                    VTDR7120_B79.Value = VTDR7120_B95.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R79.Value = VTDR7120_R79.Value - step_h;
                                        else VTDR7120_R79.Value = VTDR7120_R79.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R79.Value = VTDR7120_R79.Value - step_l;
                                        else VTDR7120_R79.Value = VTDR7120_R79.Value + step_l;
                                        /*if (VTDR7120_R127.Value <= VTDR7120_R111.Value)
                                            VTDR7120_R127.Value = VTDR7120_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G79.Value = VTDR7120_G79.Value - step_h;
                                        else VTDR7120_G79.Value = VTDR7120_G79.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G79.Value = VTDR7120_G79.Value - step_l;
                                        else VTDR7120_G79.Value = VTDR7120_G79.Value + step_l;
                                        /*if (VTDR7120_G127.Value <= VTDR7120_G111.Value)
                                            VTDR7120_G127.Value = VTDR7120_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B79.Value = VTDR7120_B79.Value - step_h;
                                        else VTDR7120_B79.Value = VTDR7120_B79.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B79.Value = VTDR7120_B79.Value - step_l;
                                        else VTDR7120_B79.Value = VTDR7120_B79.Value + step_l;
                                        /*if (VTDR7120_B127.Value <= VTDR7120_B111.Value)
                                            VTDR7120_B127.Value = VTDR7120_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 8://71
                            {
                                if (VTDR7120_R71.Value >= VTDR7120_R79.Value)
                                    VTDR7120_R71.Value = VTDR7120_R79.Value - 0xFF;
                                if (VTDR7120_G71.Value >= VTDR7120_G79.Value)
                                    VTDR7120_G71.Value = VTDR7120_G79.Value - 0xFF;
                                if (VTDR7120_B71.Value >= VTDR7120_B79.Value)
                                    VTDR7120_B71.Value = VTDR7120_B79.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R71.Value = VTDR7120_R71.Value - step_h;
                                        else VTDR7120_R71.Value = VTDR7120_R71.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R71.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R71.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R71.Value = VTDR7120_R71.Value - step_l;
                                        else VTDR7120_R71.Value = VTDR7120_R71.Value + step_l;
                                        /*if (VTDR7120_R71.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R71.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G71.Value = VTDR7120_G71.Value - step_h;
                                        else VTDR7120_G71.Value = VTDR7120_G71.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G71.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G71.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G71.Value = VTDR7120_G71.Value - step_l;
                                        else VTDR7120_G71.Value = VTDR7120_G71.Value + step_l;
                                        /*if (VTDR7120_G71.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G71.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B71.Value = VTDR7120_B71.Value - step_h;
                                        else VTDR7120_B71.Value = VTDR7120_B71.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B71.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B71.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B71.Value = VTDR7120_B71.Value - step_l;
                                        else VTDR7120_B71.Value = VTDR7120_B71.Value + step_l;
                                        /*if (VTDR7120_B71.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B71.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 9://63
                            {

                                if (VTDR7120_R63.Value >= VTDR7120_R71.Value)
                                    VTDR7120_R63.Value = VTDR7120_R71.Value - 0xFF;
                                if (VTDR7120_G63.Value >= VTDR7120_G71.Value)
                                    VTDR7120_G63.Value = VTDR7120_G71.Value - 0xFF;
                                if (VTDR7120_B63.Value >= VTDR7120_B71.Value)
                                    VTDR7120_B63.Value = VTDR7120_B71.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R63.Value = VTDR7120_R63.Value - step_h;
                                        else VTDR7120_R63.Value = VTDR7120_R63.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R63.Value = VTDR7120_R63.Value - step_l;
                                        else VTDR7120_R63.Value = VTDR7120_R63.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G63.Value = VTDR7120_G63.Value - step_h;
                                        else VTDR7120_G63.Value = VTDR7120_G63.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G63.Value = VTDR7120_G63.Value - step_l;
                                        else VTDR7120_G63.Value = VTDR7120_G63.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B63.Value = VTDR7120_B63.Value - step_h;
                                        else VTDR7120_B63.Value = VTDR7120_B63.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B63.Value = VTDR7120_B63.Value - step_l;
                                        else VTDR7120_B63.Value = VTDR7120_B63.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 10://55
                            {
                                if (VTDR7120_R55.Value >= VTDR7120_R63.Value)
                                    VTDR7120_R55.Value = VTDR7120_R63.Value - 0xFF;
                                if (VTDR7120_G55.Value >= VTDR7120_G63.Value)
                                    VTDR7120_G55.Value = VTDR7120_G63.Value - 0xFF;
                                if (VTDR7120_B55.Value >= VTDR7120_B63.Value)
                                    VTDR7120_B55.Value = VTDR7120_B63.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R55.Value = VTDR7120_R55.Value - step_h;
                                        else VTDR7120_R55.Value = VTDR7120_R55.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R55.Value = VTDR7120_R55.Value - step_l;
                                        else VTDR7120_R55.Value = VTDR7120_R55.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G55.Value = VTDR7120_G55.Value - step_h;
                                        else VTDR7120_G55.Value = VTDR7120_G55.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G55.Value = VTDR7120_G55.Value - step_l;
                                        else VTDR7120_G55.Value = VTDR7120_G55.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B55.Value = VTDR7120_B55.Value - step_h;
                                        else VTDR7120_B55.Value = VTDR7120_B55.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B55.Value = VTDR7120_B55.Value - step_l;
                                        else VTDR7120_B55.Value = VTDR7120_B55.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 11://47
                            {
                                if (VTDR7120_R47.Value >= VTDR7120_R55.Value)
                                    VTDR7120_R47.Value = VTDR7120_R55.Value - 0xFF;
                                if (VTDR7120_G47.Value >= VTDR7120_G55.Value)
                                    VTDR7120_G47.Value = VTDR7120_G55.Value - 0xFF;
                                if (VTDR7120_B47.Value >= VTDR7120_B55.Value)
                                    VTDR7120_B47.Value = VTDR7120_B55.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R47.Value = VTDR7120_R47.Value - step_h;
                                        else VTDR7120_R47.Value = VTDR7120_R47.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R47.Value)
                                            VTDR7120_R63.Value = VTDR7120_R47.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R47.Value = VTDR7120_R47.Value - step_l;
                                        else VTDR7120_R47.Value = VTDR7120_R47.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R47.Value)
                                            VTDR7120_R63.Value = VTDR7120_R47.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G47.Value = VTDR7120_G47.Value - step_h;
                                        else VTDR7120_G47.Value = VTDR7120_G47.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G47.Value)
                                            VTDR7120_G63.Value = VTDR7120_G47.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G47.Value = VTDR7120_G47.Value - step_l;
                                        else VTDR7120_G47.Value = VTDR7120_G47.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G47.Value)
                                            VTDR7120_G63.Value = VTDR7120_G47.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B47.Value = VTDR7120_B47.Value - step_h;
                                        else VTDR7120_B47.Value = VTDR7120_B47.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B47.Value)
                                            VTDR7120_B63.Value = VTDR7120_B47.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B47.Value = VTDR7120_B47.Value - step_l;
                                        else VTDR7120_B47.Value = VTDR7120_B47.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B47.Value)
                                            VTDR7120_B63.Value = VTDR7120_B47.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 12://39
                            {
                                if (VTDR7120_R39.Value >= VTDR7120_R47.Value)
                                    VTDR7120_R39.Value = VTDR7120_R47.Value - 0xFF;
                                if (VTDR7120_G39.Value >= VTDR7120_G47.Value)
                                    VTDR7120_G39.Value = VTDR7120_G47.Value - 0xFF;
                                if (VTDR7120_B39.Value >= VTDR7120_B47.Value)
                                    VTDR7120_B39.Value = VTDR7120_B47.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R39.Value = VTDR7120_R39.Value - step_h;
                                        else VTDR7120_R39.Value = VTDR7120_R39.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R39.Value = VTDR7120_R39.Value - step_l;
                                        else VTDR7120_R39.Value = VTDR7120_R39.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G39.Value = VTDR7120_G39.Value - step_h;
                                        else VTDR7120_G39.Value = VTDR7120_G39.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G39.Value = VTDR7120_G39.Value - step_l;
                                        else VTDR7120_G39.Value = VTDR7120_G39.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B39.Value = VTDR7120_B39.Value - step_h;
                                        else VTDR7120_B39.Value = VTDR7120_B39.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B39.Value = VTDR7120_B39.Value - step_l;
                                        else VTDR7120_B39.Value = VTDR7120_B39.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 13://35
                            {
                                if (VTDR7120_R35.Value >= VTDR7120_R47.Value)
                                    VTDR7120_R35.Value = VTDR7120_R47.Value - 0xFF;
                                if (VTDR7120_G35.Value >= VTDR7120_G47.Value)
                                    VTDR7120_G35.Value = VTDR7120_G47.Value - 0xFF;
                                if (VTDR7120_B35.Value >= VTDR7120_B47.Value)
                                    VTDR7120_B35.Value = VTDR7120_B47.Value - 0xFF;
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R35.Value = VTDR7120_R35.Value - step_h;
                                        else VTDR7120_R35.Value = VTDR7120_R35.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R35.Value = VTDR7120_R35.Value - step_l;
                                        else VTDR7120_R35.Value = VTDR7120_R35.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G35.Value = VTDR7120_G35.Value - step_h;
                                        else VTDR7120_G35.Value = VTDR7120_G35.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G35.Value = VTDR7120_G35.Value - step_l;
                                        else VTDR7120_G35.Value = VTDR7120_G35.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B35.Value = VTDR7120_B35.Value - step_h;
                                        else VTDR7120_B35.Value = VTDR7120_B35.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B35.Value = VTDR7120_B35.Value - step_l;
                                        else VTDR7120_B35.Value = VTDR7120_B35.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 14://31
                            {
                                if (VTDR7120_R31.Value >= VTDR7120_R35.Value)
                                    VTDR7120_R31.Value = VTDR7120_R35.Value - 0xFF;
                                if (VTDR7120_G31.Value >= VTDR7120_G35.Value)
                                    VTDR7120_G31.Value = VTDR7120_G35.Value - 0xFF;
                                if (VTDR7120_B31.Value >= VTDR7120_B35.Value)
                                    VTDR7120_B31.Value = VTDR7120_B35.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R31.Value = VTDR7120_R31.Value - step_h;
                                        else VTDR7120_R31.Value = VTDR7120_R31.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R31.Value = VTDR7120_R31.Value - step_l;
                                        else VTDR7120_R31.Value = VTDR7120_R31.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G31.Value = VTDR7120_G31.Value - step_h;
                                        else VTDR7120_G31.Value = VTDR7120_G31.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G31.Value = VTDR7120_G31.Value - step_l;
                                        else VTDR7120_G31.Value = VTDR7120_G31.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B31.Value = VTDR7120_B31.Value - step_h;
                                        else VTDR7120_B31.Value = VTDR7120_B31.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B31.Value = VTDR7120_B31.Value - step_l;
                                        else VTDR7120_B31.Value = VTDR7120_B31.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 15://27
                            {
                                if (VTDR7120_R27.Value >= VTDR7120_R31.Value)
                                    VTDR7120_R27.Value = VTDR7120_R31.Value - 0xFF;
                                if (VTDR7120_G27.Value >= VTDR7120_G31.Value)
                                    VTDR7120_G27.Value = VTDR7120_G31.Value - 0xFF;
                                if (VTDR7120_B27.Value >= VTDR7120_B31.Value)
                                    VTDR7120_B27.Value = VTDR7120_B31.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R27.Value = VTDR7120_R27.Value - step_h;
                                        else VTDR7120_R27.Value = VTDR7120_R27.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R27.Value = VTDR7120_R27.Value - step_l;
                                        else VTDR7120_R27.Value = VTDR7120_R27.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G27.Value = VTDR7120_G27.Value - step_h;
                                        else VTDR7120_G27.Value = VTDR7120_G27.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G27.Value = VTDR7120_G27.Value - step_l;
                                        else VTDR7120_G27.Value = VTDR7120_G27.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B27.Value = VTDR7120_B27.Value - step_h;
                                        else VTDR7120_B27.Value = VTDR7120_B27.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B27.Value = VTDR7120_B27.Value - step_l;
                                        else VTDR7120_B27.Value = VTDR7120_B27.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 16://23
                            {
                                if (VTDR7120_R23.Value >= VTDR7120_R27.Value)
                                    VTDR7120_R23.Value = VTDR7120_R27.Value - 0xFF;
                                if (VTDR7120_G23.Value >= VTDR7120_G27.Value)
                                    VTDR7120_G23.Value = VTDR7120_G27.Value - 0xFF;
                                if (VTDR7120_B23.Value >= VTDR7120_B27.Value)
                                    VTDR7120_B23.Value = VTDR7120_B27.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R23.Value = VTDR7120_R23.Value - step_h;
                                        else VTDR7120_R23.Value = VTDR7120_R23.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R23.Value = VTDR7120_R23.Value - step_l;
                                        else VTDR7120_R23.Value = VTDR7120_R23.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G23.Value = VTDR7120_G23.Value - step_h;
                                        else VTDR7120_G23.Value = VTDR7120_G23.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G23.Value = VTDR7120_G23.Value - step_l;
                                        else VTDR7120_G23.Value = VTDR7120_G23.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B23.Value = VTDR7120_B23.Value - step_h;
                                        else VTDR7120_B23.Value = VTDR7120_B23.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B23.Value = VTDR7120_B23.Value - step_l;
                                        else VTDR7120_B23.Value = VTDR7120_B23.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 17://19
                            {
                                if (VTDR7120_R19.Value >= VTDR7120_R23.Value)
                                    VTDR7120_R19.Value = VTDR7120_R23.Value - 0xFF;
                                if (VTDR7120_G19.Value >= VTDR7120_G23.Value)
                                    VTDR7120_G19.Value = VTDR7120_G23.Value - 0xFF;
                                if (VTDR7120_B19.Value >= VTDR7120_B23.Value)
                                    VTDR7120_B19.Value = VTDR7120_B23.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R19.Value = VTDR7120_R19.Value - step_h;
                                        else VTDR7120_R19.Value = VTDR7120_R19.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R19.Value = VTDR7120_R19.Value - step_l;
                                        else VTDR7120_R19.Value = VTDR7120_R19.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G19.Value = VTDR7120_G19.Value - step_h;
                                        else VTDR7120_G19.Value = VTDR7120_G19.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G19.Value = VTDR7120_G19.Value - step_l;
                                        else VTDR7120_G19.Value = VTDR7120_G19.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B19.Value = VTDR7120_B19.Value - step_h;
                                        else VTDR7120_B19.Value = VTDR7120_B19.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B19.Value = VTDR7120_B19.Value - step_l;
                                        else VTDR7120_B19.Value = VTDR7120_B19.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 18://15
                            {
                                if (VTDR7120_R15.Value >= VTDR7120_R19.Value)
                                    VTDR7120_R15.Value = VTDR7120_R19.Value - 0xFF;
                                if (VTDR7120_G15.Value >= VTDR7120_G19.Value)
                                    VTDR7120_G15.Value = VTDR7120_G19.Value - 0xFF;
                                if (VTDR7120_B15.Value >= VTDR7120_B19.Value)
                                    VTDR7120_B15.Value = VTDR7120_B19.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R15.Value = VTDR7120_R15.Value - step_h;
                                        else VTDR7120_R15.Value = VTDR7120_R15.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R15.Value = VTDR7120_R15.Value - step_l;
                                        else VTDR7120_R15.Value = VTDR7120_R15.Value + step_l;
                                        /*if (VTDR7120_R63.Value <= VTDR7120_R55.Value)
                                            VTDR7120_R63.Value = VTDR7120_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G15.Value = VTDR7120_G15.Value - step_h;
                                        else VTDR7120_G15.Value = VTDR7120_G15.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G15.Value = VTDR7120_G15.Value - step_l;
                                        else VTDR7120_G15.Value = VTDR7120_G15.Value + step_l;
                                        /*if (VTDR7120_G63.Value <= VTDR7120_G55.Value)
                                            VTDR7120_G63.Value = VTDR7120_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B15.Value = VTDR7120_B15.Value - step_h;
                                        else VTDR7120_B15.Value = VTDR7120_B15.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B15.Value = VTDR7120_B15.Value - step_l;
                                        else VTDR7120_B15.Value = VTDR7120_B15.Value + step_l;
                                        /*if (VTDR7120_B63.Value <= VTDR7120_B55.Value)
                                            VTDR7120_B63.Value = VTDR7120_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 19://11
                            {
                                if (VTDR7120_R11.Value >= VTDR7120_R15.Value)
                                    VTDR7120_R11.Value = VTDR7120_R15.Value - 0xFF;
                                if (VTDR7120_G11.Value >= VTDR7120_G15.Value)
                                    VTDR7120_G11.Value = VTDR7120_G15.Value - 0xFF;
                                if (VTDR7120_B11.Value >= VTDR7120_B15.Value)
                                    VTDR7120_B11.Value = VTDR7120_B15.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R11.Value = VTDR7120_R11.Value - step_h;
                                        else VTDR7120_R11.Value = VTDR7120_R11.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR7120_R11.Value <= VTDR7120_R27.Value)
                                            VTDR7120_R11.Value = VTDR7120_R27.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R11.Value = VTDR7120_R11.Value - step_l;
                                        else VTDR7120_R11.Value = VTDR7120_R11.Value + step_l;
                                        /*if (VTDR7120_R11.Value <= VTDR7120_R27.Value)
                                            VTDR7120_R11.Value = VTDR7120_R27.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G11.Value = VTDR7120_G11.Value - step_h;
                                        else VTDR7120_G11.Value = VTDR7120_G11.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR7120_G11.Value <= VTDR7120_G27.Value)
                                            VTDR7120_G11.Value = VTDR7120_G27.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G11.Value = VTDR7120_G11.Value - step_l;
                                        else VTDR7120_G11.Value = VTDR7120_G11.Value + step_l;
                                        /*if (VTDR7120_G11.Value <= VTDR7120_G27.Value)
                                            VTDR7120_G11.Value = VTDR7120_G27.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B11.Value = VTDR7120_B11.Value - step_h;
                                        else VTDR7120_B11.Value = VTDR7120_B11.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR7120_B11.Value <= VTDR7120_B27.Value)
                                            VTDR7120_B11.Value = VTDR7120_B27.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B11.Value = VTDR7120_B11.Value - step_l;
                                        else VTDR7120_B11.Value = VTDR7120_B11.Value + step_l;
                                        /*if (VTDR7120_B11.Value <= VTDR7120_B27.Value)
                                            VTDR7120_B11.Value = VTDR7120_B27.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 20://7
                            {
                                if (VTDR7120_R7.Value >= VTDR7120_R11.Value)
                                    VTDR7120_R7.Value = VTDR7120_R11.Value - 0xFF;
                                if (VTDR7120_G7.Value >= VTDR7120_G11.Value)
                                    VTDR7120_G7.Value = VTDR7120_G11.Value - 0xFF;
                                if (VTDR7120_B7.Value >= VTDR7120_B11.Value)
                                    VTDR7120_B7.Value = VTDR7120_B11.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R7.Value = VTDR7120_R7.Value - step_h;
                                        else VTDR7120_R7.Value = VTDR7120_R7.Value + step_h;
                                        adjust_Rnum = 0;

                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R7.Value = VTDR7120_R7.Value - step_l;
                                        else VTDR7120_R7.Value = VTDR7120_R7.Value + step_l;

                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G7.Value = VTDR7120_G7.Value - step_h;
                                        else VTDR7120_G7.Value = VTDR7120_G7.Value + step_h;
                                        adjust_Gnum = 0;

                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G7.Value = VTDR7120_G7.Value - step_l;
                                        else VTDR7120_G7.Value = VTDR7120_G7.Value + step_l;

                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B7.Value = VTDR7120_B7.Value - step_h;
                                        else VTDR7120_B7.Value = VTDR7120_B7.Value + step_h;
                                        adjust_Bnum = 0;

                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B7.Value = VTDR7120_B7.Value - step_l;
                                        else VTDR7120_B7.Value = VTDR7120_B7.Value + step_l;

                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 21://5
                            {

                                if (VTDR7120_R5.Value >= VTDR7120_R7.Value)
                                    VTDR7120_R5.Value = VTDR7120_R7.Value - 0xFF;
                                if (VTDR7120_G5.Value >= VTDR7120_G7.Value)
                                    VTDR7120_G5.Value = VTDR7120_G7.Value - 0xFF;
                                if (VTDR7120_B5.Value >= VTDR7120_B7.Value)
                                    VTDR7120_B5.Value = VTDR7120_B7.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R5.Value = VTDR7120_R5.Value - step_h;
                                        else VTDR7120_R5.Value = VTDR7120_R5.Value + step_h;
                                        adjust_Rnum = 0;

                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R5.Value = VTDR7120_R5.Value - step_l;
                                        else VTDR7120_R5.Value = VTDR7120_R5.Value + step_l;

                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G5.Value = VTDR7120_G5.Value - step_h;
                                        else VTDR7120_G5.Value = VTDR7120_G5.Value + step_h;
                                        adjust_Gnum = 0;

                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G5.Value = VTDR7120_G5.Value - step_l;
                                        else VTDR7120_G5.Value = VTDR7120_G5.Value + step_l;

                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B5.Value = VTDR7120_B5.Value - step_h;
                                        else VTDR7120_B5.Value = VTDR7120_B5.Value + step_h;
                                        adjust_Bnum = 0;

                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B5.Value = VTDR7120_B5.Value - step_l;
                                        else VTDR7120_B5.Value = VTDR7120_B5.Value + step_l;

                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 22://3
                            {
                                if (VTDR7120_R3.Value >= VTDR7120_R5.Value)
                                    VTDR7120_R3.Value = VTDR7120_R5.Value - 0xFF;
                                if (VTDR7120_G3.Value >= VTDR7120_G5.Value)
                                    VTDR7120_G3.Value = VTDR7120_G5.Value - 0xFF;
                                if (VTDR7120_B3.Value >= VTDR7120_B5.Value)
                                    VTDR7120_B3.Value = VTDR7120_B5.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R3.Value = VTDR7120_R3.Value - step_h;
                                        else VTDR7120_R3.Value = VTDR7120_R3.Value + step_h;
                                        adjust_Rnum = 0;

                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R3.Value = VTDR7120_R3.Value - step_l;
                                        else VTDR7120_R3.Value = VTDR7120_R3.Value + step_l;

                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G3.Value = VTDR7120_G3.Value - step_h;
                                        else VTDR7120_G3.Value = VTDR7120_G3.Value + step_h;
                                        adjust_Gnum = 0;

                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G3.Value = VTDR7120_G3.Value - step_l;
                                        else VTDR7120_G3.Value = VTDR7120_G3.Value + step_l;

                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B3.Value = VTDR7120_B3.Value - step_h;
                                        else VTDR7120_B3.Value = VTDR7120_B3.Value + step_h;
                                        adjust_Bnum = 0;

                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B3.Value = VTDR7120_B3.Value - step_l;
                                        else VTDR7120_B3.Value = VTDR7120_B3.Value + step_l;

                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 23://1
                            {
                                if (VTDR7120_R1.Value >= VTDR7120_R3.Value)
                                    VTDR7120_R1.Value = VTDR7120_R3.Value - 0xFF;
                                if (VTDR7120_G1.Value >= VTDR7120_G3.Value)
                                    VTDR7120_G1.Value = VTDR7120_G3.Value - 0xFF;
                                if (VTDR7120_B1.Value >= VTDR7120_B3.Value)
                                    VTDR7120_B1.Value = VTDR7120_B3.Value - 0xFF;

                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R1.Value = VTDR7120_R1.Value - step_h;
                                        else VTDR7120_R1.Value = VTDR7120_R1.Value + step_h;
                                        adjust_Rnum = 0;

                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR7120_R1.Value = VTDR7120_R1.Value - step_l;
                                        else VTDR7120_R1.Value = VTDR7120_R1.Value + step_l;

                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G1.Value = VTDR7120_G1.Value - step_h;
                                        else VTDR7120_G1.Value = VTDR7120_G1.Value + step_h;
                                        adjust_Gnum = 0;

                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR7120_G1.Value = VTDR7120_G1.Value - step_l;
                                        else VTDR7120_G1.Value = VTDR7120_G1.Value + step_l;

                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B1.Value = VTDR7120_B1.Value - step_h;
                                        else VTDR7120_B1.Value = VTDR7120_B1.Value + step_h;
                                        adjust_Bnum = 0;

                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR7120_B1.Value = VTDR7120_B1.Value - step_l;
                                        else VTDR7120_B1.Value = VTDR7120_B1.Value + step_l;

                                    }
                                    adjust_Bnum++;
                                }
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                                VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        default:
                            break;
                    }
                    System.Threading.Thread.Sleep(10);
                }
                catch
                {
                    T5.Enabled = false;
                    MessageBox.Show("数值超限！");
                    return;
                }
            }

        }



        private void autogamma_stop_Click(object sender, EventArgs e)
        {
            //stop_flag = 0;
            T18.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }



        //private void gamma_set_update(EventArgs e)
        //{
        //    VTDR7120_GAMMA_Click(UP_READ_GAMMA, e);
        //    System.Threading.Thread.Sleep(100);
        //    VTDR7120_GAMMA_Click(UP_GREEN_GAMMA, e);
        //    System.Threading.Thread.Sleep(100);
        //    VTDR7120_GAMMA_Click(UP_BLUE_GAMMA, e);
        //    System.Threading.Thread.Sleep(100);
        //}
        private void btnAutoGammas_VTDR7120_Click(object sender, EventArgs e)
        {
            int flag = 1;
            double Lr_d, Lg_d, Lb_d;

            gamma_set_update(e);

            D_lums = new double[14, 3];
            D_lum = new double[14];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            D_lum[0] = Convert.ToDouble(txtVT_255.Text);
            D_lum[1] = Convert.ToDouble(txtVT_223.Text);
            D_lum[2] = Convert.ToDouble(txtVT_191.Text);
            D_lum[3] = Convert.ToDouble(txtVT_127.Text);
            D_lum[4] = Convert.ToDouble(txtVT_111.Text);
            D_lum[5] = Convert.ToDouble(txtVT_79.Text);
            D_lum[6] = Convert.ToDouble(txtVT_63.Text);
            D_lum[7] = Convert.ToDouble(txtVT_55.Text);
            D_lum[8] = Convert.ToDouble(txtVT_47.Text);
            D_lum[9] = Convert.ToDouble(txtVT_39.Text);
            D_lum[10] = Convert.ToDouble(txtVT_35.Text);
            D_lum[11] = Convert.ToDouble(txtVT_31.Text);
            D_lum[12] = Convert.ToDouble(txtVT_11.Text);
            D_lum[13] = Convert.ToDouble(txtVT_3.Text);

            D_x = Convert.ToDouble(txtVT_x.Text);
            D_y = Convert.ToDouble(txtVT_y.Text);
            Lr_d = R_y * ((D_y - G_y) * (B_x - D_x) + (D_x - G_x) * (D_y - B_y)) / B_y / ((D_y - G_y) * (D_x - R_x) + (D_x - G_x) * (R_y - D_y));
            Lb_d = 1.0;
            Lg_d = G_y * ((D_y - R_y) * (B_x - D_x) + (D_x - R_x) * (D_y - B_y)) / B_y / ((D_y - R_y) * (D_x - G_x) + (D_x - R_x) * (G_y - D_y));

            for (int i = 0; i < 14; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
            }

            switch (flag)
            {
                case 1://寄存器值与亮度正比
                    {
                        lum_off = Convert.ToDouble(txtVT_loff.Text);
                        x_off = Convert.ToDouble(txtVT_xoff.Text);
                        y_off = Convert.ToDouble(txtVT_yoff.Text);

                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Red, e);
                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Green, e);
                        VTDR7120_GAMMA_Click(VTDR7120_GammaW_Blue, e);

                        OLED_Show_Click(btnwhite, e);
                        T17.Enabled = true;
                    }
                    break;
                case 2:                                           //寄存器值与亮度反比
                    break;
                default:
                    break;
            }
        }
        private void SaveCode_Click(object sender, EventArgs e)
        {
            SaveFileDialog txt = new SaveFileDialog();
            txt.Filter = @"txt文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            string str = "//-----保存Driver IC Code文件------\r\n";
            if (txt.ShowDialog() == DialogResult.OK)
            {
                if (txt.FileName == " ")
                {
                    return;
                }
                StreamWriter sw = null; //文件流
                sw = new StreamWriter(txt.FileName, false, Encoding.Default);//Encoding.GetEncoding("UTF-8")
                try
                {
                    if (ChkCMD1.Checked)
                    {
                        str += "//---CMD1---\r\n" + txtCmd1.Text;// lstMIPIDriver.Items[i].ToString();
                        str += "\r\n\r\n";
                    }
                    if (ChkCMD2.Checked)
                    {
                        str += "//---CMD2---\r\n" + txtCmd2.Text;// lstMIPIDriver.Items[i].ToString();
                        str += "\r\n\r\n";
                    }
                    if (ChkCMD3.Checked)
                    {
                        str += "//---CMD3---\r\n" + txtCmd3.Text;// lstMIPIDriver.Items[i].ToString();
                        str += "\r\n\r\n";
                    }
                    if (ChkCMD4.Checked)
                    {
                        str += "//---CMD4---\r\n" + txtCmd4.Text;// lstMIPIDriver.Items[i].ToString();
                        str += "\r\n\r\n";
                    }

                    sw.Write(str);
                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Driver IC Code保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Driver IC Code保存时发生错误，请再试！", "系统提示：");
                }
            }

        }
        private void Send_Cmd_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            switch (btn.Name)
            {
                case "btnSend1":
                    {
                        MainForm.txtProcessDrivercode(txtCmd1.Text, out string txtbaseClearOriginal, out string txtMCleatOriginal);
                    }
                    break;
                case "btnSend2":
                    {
                        MainForm.txtProcessDrivercode(txtCmd2.Text, out string txtbaseClearOriginal, out string txtMCleatOriginal);
                    }
                    break;
                case "btnSend3":
                    {
                        MainForm.txtProcessDrivercode(txtCmd3.Text, out string txtbaseClearOriginal, out string txtMCleatOriginal);
                    }
                    break;
                case "btnSend4":
                    {
                        MainForm.txtProcessDrivercode(txtCmd4.Text, out string txtbaseClearOriginal, out string txtMCleatOriginal);
                    }
                    break;

                case "btnSend5":
                    {
                        MainForm.txtProcessDrivercode(txtCmd5.Text, out string txtbaseClearOriginal, out string txtMCleatOriginal);
                    }
                    break;

            }
            Setting.TempRecord.cmdLen = 6;
            if (Write_LP.Checked)
            {
                MainForm.SendCmd(0);
            }
            else
            {
                MainForm.SendCmd(4);
            }
            textBox1.Text += "命令已下发...\r\n";
            textBox1.Select(textBox1.Text.Length, 0);
            textBox1.ScrollToCaret();
        }
        private void OpenTxtCode_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            OpenFileDialog of = new OpenFileDialog();
            of.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            of.Title = "初始化 Code";

            if (of.ShowDialog() == DialogResult.OK)
            {
                StreamReader streamReader = new StreamReader(of.FileName, Encoding.Default);
                switch (btn.Name)
                {
                    case "OpenTxtCode":
                        {
                            txtCmd1.Clear();
                            txtCmd1.Text = streamReader.ReadToEnd();
                        }
                        break;
                    case "OpenTxtCode2":
                        {
                            txtCmd2.Clear();
                            txtCmd2.Text = streamReader.ReadToEnd();
                        }
                        break;
                    case "OpenTxtCode3":
                        {
                            txtCmd3.Clear();
                            txtCmd3.Text = streamReader.ReadToEnd();
                        }
                        break;
                    case "OpenTxtCode4":
                        {
                            txtCmd4.Clear();
                            txtCmd4.Text = streamReader.ReadToEnd();
                        }
                        break;
                    default: break;
                }
                streamReader.Close();
            }
        }
        private void btnSaveDriverCode_Click(object sender, EventArgs e)
        {

        }
        //写Gamma page
        private void Write_gamma_x(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Int32 DataNum;
            VTDR7120_txtRegData.Text = "f0,aa,13";
            string strLine = Convert.ToString(VTDR7120_txtRegData.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组
            {
                Setting.TempRecord.cmdLen = arr.Length + 5;
                Send_buf = new byte[arr.Length + 5];
                Send_buf[0] = 0x60;//VTDR7120
                Send_buf[1] = 0x01;
                Send_buf[2] = byte.Parse(arr.Length.ToString());
                for (int i = 0; i < arr.Length; i++)
                {
                    Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                }
                CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                try
                {
                    MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                }
            }
            Thread.Sleep(100);
            VTDR7120_txtRegData.Text = "bf,00";
            strLine = Convert.ToString(VTDR7120_txtRegData.Text);
            arr = strLine.Split(','); //以逗号分割，添加到数组
            {
                Setting.TempRecord.cmdLen = arr.Length + 5;
                Send_buf = new byte[arr.Length + 5];
                Send_buf[0] = 0x60;//VTDR7120
                Send_buf[1] = 0x01;
                Send_buf[2] = 0x02;
                Send_buf[3 + 0] = 0xbf;
                Send_buf[3 + 1] = Convert.ToByte(VTDR7120_Gamma_Group.Value);
                CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                try
                {
                    MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                }
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }
        private void btn6Gammas_VTDR7120_DLL_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            int VT_Flag = 0;
            Class1 gma = new Class1();
            int[] Rcode = new int[13] {Convert.ToInt32(VTDR7120_R11.Text, 16),Convert.ToInt32(VTDR7120_R31.Text, 16),Convert.ToInt32(VTDR7120_R35.Text, 16),Convert.ToInt32(VTDR7120_R39.Text, 16),Convert.ToInt32(VTDR7120_R47.Text, 16),
                                       Convert.ToInt32(VTDR7120_R55.Text, 16), Convert.ToInt32(VTDR7120_R63.Text, 16) ,Convert.ToInt32(VTDR7120_R79.Text, 16),Convert.ToInt32(VTDR7120_R111.Text, 16), Convert.ToInt32(VTDR7120_R127.Text, 16) ,
                                       Convert.ToInt32(VTDR7120_R191.Text, 16),Convert.ToInt32(VTDR7120_R223.Text, 16),Convert.ToInt32(VTDR7120_R255.Text, 16) };

            int[] Gcode = new int[13] {Convert.ToInt32(VTDR7120_G11.Text, 16),Convert.ToInt32(VTDR7120_G31.Text, 16),Convert.ToInt32(VTDR7120_G35.Text, 16),Convert.ToInt32(VTDR7120_G39.Text, 16),Convert.ToInt32(VTDR7120_G47.Text, 16),
                                       Convert.ToInt32(VTDR7120_G55.Text, 16), Convert.ToInt32(VTDR7120_G63.Text, 16) ,Convert.ToInt32(VTDR7120_G79.Text, 16),Convert.ToInt32(VTDR7120_G111.Text, 16), Convert.ToInt32(VTDR7120_G127.Text, 16) ,
                                       Convert.ToInt32(VTDR7120_G191.Text, 16),Convert.ToInt32(VTDR7120_G223.Text, 16),Convert.ToInt32(VTDR7120_G255.Text, 16) };

            int[] Bcode = new int[13] {Convert.ToInt32(VTDR7120_B11.Text, 16),Convert.ToInt32(VTDR7120_B31.Text, 16),Convert.ToInt32(VTDR7120_B35.Text, 16),Convert.ToInt32(VTDR7120_B39.Text, 16),Convert.ToInt32(VTDR7120_B47.Text, 16),
                                       Convert.ToInt32(VTDR7120_B55.Text, 16), Convert.ToInt32(VTDR7120_B63.Text, 16) ,Convert.ToInt32(VTDR7120_B79.Text, 16),Convert.ToInt32(VTDR7120_B111.Text, 16), Convert.ToInt32(VTDR7120_B127.Text, 16) ,
                                       Convert.ToInt32(VTDR7120_B191.Text, 16),Convert.ToInt32(VTDR7120_B223.Text, 16),Convert.ToInt32(VTDR7120_B255.Text, 16)  };

            double[] Lcode = new double[13] { double.Parse(this.CAS200_dataGridView.Rows[12].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[11].Cells[3].Value.ToString()),double.Parse(this.CAS200_dataGridView.Rows[10].Cells[3].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[9].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[8].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[7].Cells[3].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[6].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[5].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[4].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[3].Cells[3].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[2].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[1].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[0].Cells[3].Value.ToString()) };

            double[] xcode = new double[13] {double.Parse(this.CAS200_dataGridView.Rows[12].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[11].Cells[1].Value.ToString()),double.Parse(this.CAS200_dataGridView.Rows[10].Cells[1].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[9].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[8].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[7].Cells[1].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[6].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[5].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[4].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[3].Cells[1].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[2].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[1].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[0].Cells[1].Value.ToString()) };

            double[] ycode = new double[13] {double.Parse(this.CAS200_dataGridView.Rows[12].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[11].Cells[2].Value.ToString()),double.Parse(this.CAS200_dataGridView.Rows[10].Cells[2].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[9].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[8].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[7].Cells[2].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[6].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[5].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[4].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[3].Cells[2].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[2].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[1].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[0].Cells[2].Value.ToString()) };

            int[,] RGB_Code = new int[3, 13];
            double[,] RGB_Lxy = new double[3, 13];

            for (int i = 0; i < 13; i++)
            {
                RGB_Code[0, i] = Rcode[i];
                RGB_Code[1, i] = Gcode[i];
                RGB_Code[2, i] = Bcode[i];

                RGB_Lxy[0, i] = Lcode[i];
                RGB_Lxy[1, i] = xcode[i];
                RGB_Lxy[2, i] = ycode[i];
            }
            int totalpoint = 13;
            int HBMmodebyGma = Convert.ToUInt16(text_HBMmodebyGma.Text);
            double NormalLum = Convert.ToDouble(text_NormalLum.Text);
            int LowLumbyGma = Convert.ToUInt16(text_LowLumbyGma.Text);
            int maxdbv = Convert.ToUInt16(text_Maxdbv.Text);

            //initail first
            //NormalLum is the luminance for dbv=255, HBMmodebyGma need to be set 1
            //gma.GMA_Tool_init(RGB_Code, RGB_Lxy, point5or6, NormalLum, HBMmodebyGma);
            gma.GMA_Tool_init(RGB_Code, RGB_Lxy, totalpoint, maxdbv, NormalLum, HBMmodebyGma, LowLumbyGma);

            int[,] GMA_CodeR = new int[9, 25];
            int[,] GMA_CodeG = new int[9, 25];
            int[,] GMA_CodeB = new int[9, 25];
            int[] dbvpoint = new int[11];
            int gmanumber = 0;

            int[,] GMA_CodeR22 = new int[9, 25];
            int[,] GMA_CodeG22 = new int[9, 25];
            int[,] GMA_CodeB22 = new int[9, 25];

            //for AOD luminance gamma code
            int codeR = 0, codeG = 0, codeB = 0;
            switch (btnTmp.Name)
            {
                case "VT_DLL_NORMAL":
                    {
                        gma.GMA_process(ref GMA_CodeR, ref GMA_CodeG, ref GMA_CodeB, ref dbvpoint, ref gmanumber);
                        VT_Flag = 1;
                    }
                    break;

                case "VT_Gamma2_2":
                    {
                        gma.GMA_process(ref GMA_CodeR, ref GMA_CodeG, ref GMA_CodeB, ref dbvpoint, ref gmanumber);
                        //use the same dbvpoint and gamma number
                        gma.GMA_process2_2(dbvpoint, gmanumber, ref GMA_CodeR22, ref GMA_CodeG22, ref GMA_CodeB22, maxdbv, NormalLum);
                        VT_Flag = 2;
                    }
                    break;
                case "VT_AOD_LUM":
                    {
                        gma.GMA_process(ref GMA_CodeR, ref GMA_CodeG, ref GMA_CodeB, ref dbvpoint, ref gmanumber);

                        gma.GMA_CodebyLum(30, ref codeR, ref codeG, ref codeB);
                        VT_Flag = 3;
                    }
                    break;

                default:
                    break;
            }

            if ((VT_Flag == 1) || (VT_Flag == 2) || (VT_Flag == 3))
            {
                SaveFileDialog sf = new SaveFileDialog(); //对话框
                sf.Filter = @"txt文件(*.txt)|*.txt|所有文件(*.*)|*.*"; //定义保存的文件的类型
                string str = "保存VT Driver IC Gamma Code文件";
                if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
                {
                    if (sf.FileName == "") return; //如果没有输入文件名
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    try
                    {
                        //printf 原始的初始化code
                        for (int i = 0; i < (MainForm.lstMIPIDriver.Items.Count - 2); i++)     //IC 初始化代码
                        {
                            str = MainForm.lstMIPIDriver.Items[i].ToString();
                            sw.WriteLine(str);
                        }
                        if (VT_Flag == 1)
                        {
                            str = "F0,AA,11";
                            sw.WriteLine(str);
                            str = "C3," + (dbvpoint[0] & 0xFF).ToString("X2") + "," + (dbvpoint[1] & 0xFF).ToString("X2") + "," + (dbvpoint[2] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[3] & 0xFF).ToString("X2") + "," + (dbvpoint[4] & 0xFF).ToString("X2") + "," + (dbvpoint[5] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[6] & 0xFF).ToString("X2") + "," + (dbvpoint[7] & 0xFF).ToString("X2") + "," + (dbvpoint[8] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[9] & 0xFF).ToString("X2") + "," + (dbvpoint[10] & 0xFF).ToString("X2") + ","
                                       + (((dbvpoint[0] & 0x100) >> 1) + ((dbvpoint[1] & 0x100) >> 2) + ((dbvpoint[2] & 0x100) >> 3) + ((dbvpoint[3] & 0x100) >> 4) + ((dbvpoint[4] & 0x100) >> 5)
                                       + ((dbvpoint[5] & 0x100) >> 6) + ((dbvpoint[6] & 0x100) >> 7) + ((dbvpoint[7] & 0x100) >> 8)).ToString("X2") + ","
                                       + (((dbvpoint[8] & 0x100) >> 6) + ((dbvpoint[9] & 0x100) >> 7) + ((dbvpoint[10] & 0x100) >> 8)).ToString("X2");
                            sw.WriteLine(str);

                            str = "F0,AA,13";
                            sw.WriteLine(str);

                            for (int i = 0; i <= 7; i++)
                            {
                                if ((i > gmanumber) && (i != 7))
                                    continue;

                                str = "BF," + i.ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma R
                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);



                            }
                            if (HBMmodebyGma == 0)
                            {
                                str = "BF," + "08";
                                sw.WriteLine(str);

                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR[7, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG[7, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB[7, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                            }
                            if (HBMmodebyGma == 1)
                            {
                                str = "BF," + "08";
                                sw.WriteLine(str);

                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR[8, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG[8, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB[8, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                            }
                            str = "11";
                            sw.WriteLine(str);
                            str = "29";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                            VT_Flag = 0;
                            MessageBox.Show("VT Driver IC Gamma Code保存OK！", "系统提示：");
                        }
                        else if (VT_Flag == 2)
                        {
                            str = "F0,AA,11";
                            sw.WriteLine(str);
                            str = "C3," + (dbvpoint[0] & 0xFF).ToString("X2") + "," + (dbvpoint[1] & 0xFF).ToString("X2") + "," + (dbvpoint[2] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[3] & 0xFF).ToString("X2") + "," + (dbvpoint[4] & 0xFF).ToString("X2") + "," + (dbvpoint[5] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[6] & 0xFF).ToString("X2") + "," + (dbvpoint[7] & 0xFF).ToString("X2") + "," + (dbvpoint[8] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[9] & 0xFF).ToString("X2") + "," + (dbvpoint[10] & 0xFF).ToString("X2") + ","
                                       + (((dbvpoint[0] & 0x100) >> 1) + ((dbvpoint[1] & 0x100) >> 2) + ((dbvpoint[2] & 0x100) >> 3) + ((dbvpoint[3] & 0x100) >> 4) + ((dbvpoint[4] & 0x100) >> 5)
                                       + ((dbvpoint[5] & 0x100) >> 6) + ((dbvpoint[6] & 0x100) >> 7) + ((dbvpoint[7] & 0x100) >> 8)).ToString("X2") + ","
                                       + (((dbvpoint[8] & 0x100) >> 6) + ((dbvpoint[9] & 0x100) >> 7) + ((dbvpoint[10] & 0x100) >> 8)).ToString("X2");
                            sw.WriteLine(str);

                            str = "F0,AA,13";
                            sw.WriteLine(str);

                            for (int i = 0; i <= 7; i++)
                            {
                                if ((i > gmanumber) && (i != 7))
                                    continue;

                                str = "BF," + i.ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma R
                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR22[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG22[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB22[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                            }
                            str = "11";
                            sw.WriteLine(str);
                            str = "29";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                            VT_Flag = 0;
                            MessageBox.Show("VT Driver IC Gamma Code保存OK！", "系统提示：");
                        }
                        else
                        {
                            str = "F0,AA,13";
                            sw.WriteLine(str);

                            str = "C0," + "00," + "00,";
                            str = str + ((codeR & 0x300) >> 8).ToString("X2") + "," + (codeR & 0xFF).ToString("X2") + ",";
                            str = str + "00," + "00," + "00," + "00";
                            sw.WriteLine(str);

                            str = "C1," + "00," + "00,";
                            str = str + ((codeG & 0x300) >> 8).ToString("X2") + "," + (codeG & 0xFF).ToString("X2") + ",";
                            str = str + "00," + "00," + "00," + "00";
                            sw.WriteLine(str);

                            str = "C2," + "00," + "00,";
                            str = str + ((codeB & 0x300) >> 8).ToString("X2") + "," + (codeB & 0xFF).ToString("X2") + ",";
                            str = str + "00," + "00," + "00," + "00";
                            sw.WriteLine(str);
                            str = "11";
                            sw.WriteLine(str);
                            str = "29";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                            VT_Flag = 0;
                            MessageBox.Show("VT Driver IC Gamma Code保存OK！", "系统提示：");

                        }

                    }
                    catch
                    {
                        MessageBox.Show("VT Driver IC Gamma Code保存时发生错误，请再试！", "系统提示：");
                    }
                }
            }
        }
        private void btn_Pic_Load_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fldb = new FolderBrowserDialog();
            fldb.ShowNewFolderButton = false;
            DialogResult res = fldb.ShowDialog();
            if (res != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("没选择任何文件夹.");
                return;
            }
            string path = fldb.SelectedPath;
            if (!Directory.Exists(path))
            {
                MessageBox.Show("文件夹不存在.");
                return;
            }
            DirectoryInfo da = new DirectoryInfo(path);
            //this.listBox3_BMPFile.Items.Clear();
            this.CreateListItem(da);//递归加载文件夹里的所有图片
            Pic_Box.Text = path;
            vesa_bmp_path = path;
            textBox2.Text = path;
        }
        // 送图调节首位为 0x5A     TemFileContent[0] = 0x5A;
        string vesa_bmp_path;
        private void VTDR7120_btnPrevPic_Run(string filenames)
        {
            Int32 HACT_True = 0;
            Int32 VACT_True = 0;
            Int32 m_txlen = 0;
            Int32 j = 0;
            //byte[] TemFileContent = new byte[1024 * 300];
            byte[] TemFileContent = new byte[512 * 4000 + 100];

            System.Int32 ByteReaded = 0x00;
            try
            {
                string FileName;
                //string FileName = textBox2.Text + '\\' + listBox3_BMPFile.SelectedItem.ToString(); // vesa_bmp_path
                if (Vesa_Check.Checked == true)
                {
                    FileName = vesa_bmp_path + '\\' + filenames;
                }
                else
                {
                    FileName = System.Windows.Forms.Application.StartupPath + "\\Resources\\" + filenames;
                }
                //string FileName = vesa_bmp_path + '\\' + filenames;
                FileStream aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                ByteReaded = aFile.Read(TemFileContent, 0, 54);
                HACT_True = (Convert.ToInt32(TemFileContent[19]) << 8) + TemFileContent[18];
                VACT_True = Convert.ToInt32((TemFileContent[23] << 8) + TemFileContent[22]);
                j = 1;
                //===========很重要的一句话==========
                //------------20180808---------------
                try
                { //5a a5 9DF0731A-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
                    TemFileContent[0] = 0xbd; TemFileContent[1] = 0x5a; TemFileContent[2] = 0xa5; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
                    MainForm.comPort.Write(TemFileContent, 0, 5);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                    return;
                }
                //==================================
                //if ((HACT_True == ((TemFileContent[19] << 8) + (TemFileContent[18]))) && (Convert.ToInt32(VACT.Value) == (TemFileContent[23] << 8) + (TemFileContent[22])))//BMP图片水平大小
                {
                    aFile.Seek(54, SeekOrigin.Begin);
                    while (j <= VACT_True)
                    {
                        if (HACT_True % 4 != 0)
                            aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
                        else
                            aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);
                        ByteReaded = aFile.Read(TemFileContent, 0, HACT_True * 3);
                        try
                        {
                            MainForm.comPort.Write(TemFileContent, 0, ByteReaded);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                            break;
                        }
                        m_txlen += ByteReaded;
                        progressBar1.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
                        label14.Text = progressBar1.Value.ToString() + "%";
                        Application.DoEvents();//重点，必须加上，否则父子窗体都假死
                        j++;
                    }
                    TemFileContent[0] = 0x5A;
                    try
                    {
                        MainForm.comPort.Write(TemFileContent, 0, 1);
                    }
                    catch
                    {
                        MessageBox.Show("串口有误，请检查", "错误");
                    }

                    aFile.Close();
                }
                /*
                else
                {
                    MessageBox.Show("BMP分辨率非法");
                }*/
            }
            catch
            {
                MessageBox.Show("请选择文件夹", "错误");
            }
        }


        //---Gamma绑点数据，这里的数据仅供参考---
        private int[] Point_VTDR7120 = new int[24] { 255, 223, 191, 159, 127, 111, 95, 79, 71, 63, 55, 47, 39, 35, 31, 27, 23, 19, 15, 11, 7, 5, 3, 1 };
        //Demura hex data to SRAM


        //11位数据传输
        //private void PreLoad_Demura_data_Click(object sender, EventArgs e)  //预加载Demura文件//private void PreLoad_Demura_data_Click(object sender, EventArgs e)  //预加载Demura文件
        //{
        //    Int32 m_txlen = 0;
        //    Int32 Once_txlen = 0;
        //    Int32 File_Length, File_Length_tep;
        //    bool tx_en = true;
        //    byte[] TemFileContent = new byte[1024 * 100];
        //    char[] Acsii_array = new char[2];
        //    Int32 div = 0;
        //    TemFileContent[0] = 0x5B;
        //    TemFileContent[1] = 0x01;
        //    div = Convert.ToInt16(MainForm.HACT.Value) * 3;

        //    //TemFileContent[1] = 0xbd;
        //    //TemFileContent[2] = 0xcf;
        //    System.Int32 ByteReaded;

        //    try
        //    {
        //        string FileName = textBox5.Text + '\\' + listBox3_Demura_File.SelectedItem.ToString();
        //        FileStream aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        //        File_Length = Convert.ToInt32(aFile.Length);
        //        File_Length_tep = File_Length;
        //        //USB_Rx_Buffer[0]==BMP_FLAG)&&(USB_Rx_Buffer[1]==0x5b)&&(USB_Rx_Buffer[2]==0xb5)&&(USB_Rx_Buffer[3]==0xd9)&&(USB_Rx_Buffer[4]==0x9d))
        //        textBox1.Text += "设定 Demura Flag \r\n";
        //        try
        //        { //Demura 告诉下位机Demura数据搬运开始
        //            TemFileContent[2] = 0xbd;
        //            TemFileContent[3] = 0xcf;
        //            TemFileContent[4] = 0xfc;
        //            TemFileContent[5] = 0xac;
        //            TemFileContent[6] = 0xca;
        //            TemFileContent[7] = Convert.ToByte(File_Length >> 24);
        //            TemFileContent[8] = Convert.ToByte((File_Length >> 16) & 0xff);
        //            TemFileContent[9] = Convert.ToByte((File_Length >> 8) & 0xff);
        //            TemFileContent[10] = Convert.ToByte(File_Length & 0xff);
        //            MainForm.comPort.Write(TemFileContent, 0, 11);
        //        }
        //        catch
        //        {
        //            MessageBox.Show("串口有误，请检查", "错误");
        //            tx_en = false;
        //            return;
        //        }

        //        while (tx_en)
        //        {
        //            if (File_Length_tep > (File_Length % div))
        //            {
        //                Once_txlen = div;
        //            }
        //            else  //最后一笔
        //            {
        //                Once_txlen = Convert.ToInt32(aFile.Length % div);
        //                tx_en = false;
        //            }
        //            aFile.Seek(0 + m_txlen, SeekOrigin.Begin);    //跳转
        //            ByteReaded = aFile.Read(TemFileContent, 0, Once_txlen); // 存入第五位
        //            try
        //            {
        //                MainForm.comPort.Write(TemFileContent, 0, ByteReaded + 0);
        //            }
        //            catch
        //            {
        //                MessageBox.Show("串口有误，请检查", "错误");
        //                tx_en = false;
        //                break;
        //            }
        //            //tx_en = false;
        //            m_txlen += ByteReaded;
        //            progressBar2.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
        //            label_flash.Text = progressBar2.Value.ToString() + "%";
        //            Application.DoEvents();//重点，必须加上，否则父子窗体都假死
        //            File_Length_tep = File_Length_tep - div;
        //        }
        //        aFile.Close();
        //        //try  
        //        //{   //Demura 数据搬运结束
        //        //    TemFileContent[0] = 0x5b;                    
        //        //    MainForm.comPort.Write(TemFileContent, 0,1);
        //        //}
        //        //catch
        //        //{
        //        //    MessageBox.Show("串口有误，请检查", "错误");
        //        //    tx_en = false;
        //        //    return;
        //        //}
        //    }
        //    catch
        //    {
        //        MessageBox.Show("请选择文件夹", "错误");
        //    }
        //}


        //9位数据传输
        private void PreLoad_Demura_data_Click(object sender, EventArgs e)  //预加载Demura文件//private void PreLoad_Demura_data_Click(object sender, EventArgs e)  //预加载Demura文件
        {
            Int32 m_txlen = 0;
            Int32 Once_txlen = 0;
            Int32 File_Length, File_Length_tep;
            bool tx_en = true;
            byte[] TemFileContent = new byte[1024 * 100];
            char[] Acsii_array = new char[2];
            Int32 div = 0;

            div = Convert.ToInt16(MainForm.HACT.Value) * 3;
            System.Int32 ByteReaded;

            try
            {
                string FileName = textBox5.Text + '\\' + listBox3_Demura_File.SelectedItem.ToString();
                FileStream aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                File_Length = Convert.ToInt32(aFile.Length);
                File_Length_tep = File_Length;
                //USB_Rx_Buffer[0]==BMP_FLAG)&&(USB_Rx_Buffer[1]==0x5b)&&(USB_Rx_Buffer[2]==0xb5)&&(USB_Rx_Buffer[3]==0xd9)&&(USB_Rx_Buffer[4]==0x9d))
                textBox1.Text += "设定 Demura Flag \r\n";
                try
                { //Demura 告诉下位机Demura数据搬运开始
                    TemFileContent[0] = 0xbd;
                    TemFileContent[1] = 0x5B;
                    TemFileContent[2] = 0xb5;
                    TemFileContent[3] = 0xd9;
                    TemFileContent[4] = 0x9d;
                    TemFileContent[5] = Convert.ToByte(File_Length >> 24);
                    TemFileContent[6] = Convert.ToByte((File_Length >> 16) & 0xff);
                    TemFileContent[7] = Convert.ToByte((File_Length >> 8) & 0xff);
                    TemFileContent[8] = Convert.ToByte(File_Length & 0xff);
                    MainForm.comPort.Write(TemFileContent, 0, 9);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                    tx_en = false;
                    return;
                }

                while (tx_en)
                {
                    if (File_Length_tep > (File_Length % div))
                    {
                        Once_txlen = div;
                    }
                    else  //最后一笔
                    {
                        Once_txlen = Convert.ToInt32(aFile.Length % div);
                        tx_en = false;
                    }
                    aFile.Seek(0 + m_txlen, SeekOrigin.Begin);    //跳转
                    ByteReaded = aFile.Read(TemFileContent, 0, Once_txlen); // 存入第五位
                    try
                    {
                        MainForm.comPort.Write(TemFileContent, 0, ByteReaded + 0);
                    }
                    catch
                    {
                        MessageBox.Show("串口有误，请检查", "错误");
                        tx_en = false;
                        break;
                    }
                    //tx_en = false;
                    m_txlen += ByteReaded;
                    progressBar2.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
                    label_flash.Text = progressBar2.Value.ToString() + "%";
                    Application.DoEvents();//重点，必须加上，否则父子窗体都假死
                    File_Length_tep = File_Length_tep - div;
                }
                aFile.Close();
                //try  
                //{   //Demura 数据搬运结束
                //    TemFileContent[0] = 0x5b;                    
                //    MainForm.comPort.Write(TemFileContent, 0,1);
                //}
                //catch
                //{
                //    MessageBox.Show("串口有误，请检查", "错误");
                //    tx_en = false;
                //    return;
                //}
            }
            catch
            {
                MessageBox.Show("请选择文件夹", "错误");
            }
        }



        private void Load_Demura_data_Click1(object sender, EventArgs e)
        {

        }
        //private void Load_Demura_data_Click1(object sender, EventArgs e)
        //{
        //    Int32 m_txlen = 0;
        //    Int32 Once_txlen = 0;
        //    Int32 File_Length, File_Length_tep;
        //    bool tx_en = true;
        //    byte[] TemFileContent = new byte[1024 * 100];
        //    char[] Acsii_array = new char[2];
        //    Int32 div = 0;

        //    div = Convert.ToInt16(MainForm.HACT.Value) * 3;
        //    System.Int32 ByteReaded = 0x00;
        //    try
        //    {
        //        string FileName = textBox5.Text + '\\' + listBox3_Demura_File.SelectedItem.ToString();
        //        FileStream aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        //        File_Length = Convert.ToInt32(aFile.Length);
        //        File_Length_tep = File_Length;

        //        while (tx_en)
        //        {
        //            if (File_Length_tep > (File_Length % div))
        //            {
        //                Once_txlen = div;
        //            }
        //            else  //最后一笔
        //            {
        //                Once_txlen = Convert.ToInt32(aFile.Length % div);
        //                tx_en = false;
        //            }
        //            aFile.Seek(0 + m_txlen, SeekOrigin.Begin);    //跳转
        //            ByteReaded = aFile.Read(TemFileContent, 9, Once_txlen); // 存入第9位
        //            try
        //            {
        //                //TemFileContent[0] = 0x5B;
        //                //TemFileContent[1] = Convert.ToByte(File_Length >> 24);
        //                //TemFileContent[2] = Convert.ToByte((File_Length >> 16) & 0xff);
        //                //TemFileContent[3] = Convert.ToByte((File_Length >> 8) & 0xff);
        //                //TemFileContent[4] = Convert.ToByte(File_Length & 0xff);
        //                //MainForm.comPort.Write(TemFileContent, 0, ByteReaded + 5);

        //                TemFileContent[0] = 0xbd;
        //                TemFileContent[1] = 0x5B;
        //                TemFileContent[2] = 0xb5;
        //                TemFileContent[3] = 0xd9;
        //                TemFileContent[4] = 0x9d;
        //                TemFileContent[5] = Convert.ToByte(File_Length >> 24);
        //                TemFileContent[6] = Convert.ToByte((File_Length >> 16) & 0xff);
        //                TemFileContent[7] = Convert.ToByte((File_Length >> 8) & 0xff);
        //                TemFileContent[8] = Convert.ToByte(File_Length & 0xff);
        //                MainForm.comPort.Write(TemFileContent, 0, ByteReaded + 9);
        //            }
        //            catch
        //            {
        //                MessageBox.Show("串口有误，请检查", "错误");
        //                tx_en = false;
        //                break;
        //            }
        //            //tx_en = false;
        //            m_txlen += ByteReaded;
        //            Application.DoEvents();//重点，必须加上，否则父子窗体都假死
        //            File_Length_tep = File_Length_tep - div;
        //        }
        //        aFile.Close();
        //    }
        //    catch
        //    {
        //        MessageBox.Show("请选择文件夹", "错误");
        //    }
        //}
        private void Load_Demura_data_Click2(object sender, EventArgs e)
        {
            Int32 m_txlen = 0;
            Int32 Once_txlen = 0;
            Int32 File_Length, File_Length_tep;
            bool tx_en = true;
            byte[] TemFileContent = new byte[1024 * 100];
            char[] Acsii_array = new char[2];
            Int32 div = 0;
            div = Convert.ToInt16(MainForm.HACT.Value) * 3;
            System.Int32 ByteReaded = 0x00;
            try
            {
                string FileName = textBox5.Text + '\\' + listBox3_Demura_File.SelectedItem.ToString();
                FileStream aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                File_Length = Convert.ToInt32(aFile.Length) - 0x180000;
                File_Length_tep = File_Length;
                Int32 RM6935x_Demura_part2_addr = 0x180000; //第二笔补偿数据起始地址
                                                            // Int32 RM6935x_Demura_part2_length = 0x17ffff;//第二笔补偿数据总长，256取整
                                                            //File_Length_tep = RM6935x_Demura_part2_length;
                                                            //File_Length = RM6935x_Demura_part2_length;
                while (tx_en)
                {
                    if (File_Length_tep > (File_Length % div))
                    {
                        Once_txlen = div;
                    }
                    else  //最后一笔
                    {
                        Once_txlen = Convert.ToInt32(File_Length % div);
                        tx_en = false;
                    }
                    aFile.Seek(RM6935x_Demura_part2_addr + m_txlen, SeekOrigin.Begin);    //跳转
                    ByteReaded = aFile.Read(TemFileContent, 9, Once_txlen); // 存入第9位
                    try
                    {
                        //TemFileContent[0] = 0x5B;
                        //TemFileContent[1] = Convert.ToByte(File_Length >> 24);
                        //TemFileContent[2] = Convert.ToByte((File_Length >> 16) & 0xff);
                        //TemFileContent[3] = Convert.ToByte((File_Length >> 8) & 0xff);
                        //TemFileContent[4] = Convert.ToByte(File_Length & 0xff);
                        //MainForm.comPort.Write(TemFileContent, 0, Once_txlen + 5);

                        TemFileContent[0] = 0xbd;
                        TemFileContent[1] = 0x5B;
                        TemFileContent[2] = 0xb5;
                        TemFileContent[3] = 0xd9;
                        TemFileContent[4] = 0x9d;
                        TemFileContent[5] = Convert.ToByte(File_Length >> 24);
                        TemFileContent[6] = Convert.ToByte((File_Length >> 16) & 0xff);
                        TemFileContent[7] = Convert.ToByte((File_Length >> 8) & 0xff);
                        TemFileContent[8] = Convert.ToByte(File_Length & 0xff);
                        MainForm.comPort.Write(TemFileContent, 0, Once_txlen + 9);

                    }
                    catch
                    {
                        MessageBox.Show("串口有误，请检查", "错误");
                        tx_en = false;
                        break;
                    }
                    //tx_en = false;
                    m_txlen += ByteReaded;
                    Application.DoEvents();
                    File_Length_tep = File_Length_tep - div;
                }
                aFile.Close();
            }
            catch
            {
                MessageBox.Show("请选择文件夹", "错误");
            }
        }
        private void Load_Demura_data_Click3(object sender, EventArgs e)
        {
            Int32 m_txlen = 0;
            Int32 Once_txlen = 0;
            Int32 File_Length, File_Length_tep;
            bool tx_en = true;
            byte[] TemFileContent = new byte[1024 * 100];
            char[] Acsii_array = new char[2];
            Int32 div = 0;
            div = Convert.ToInt16(MainForm.HACT.Value) * 3;
            System.Int32 ByteReaded = 0x00;
            try
            {
                string FileName = textBox5.Text + '\\' + listBox3_Demura_File.SelectedItem.ToString();
                FileStream aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                //File_Length = Convert.ToInt32(aFile.Length);
                //File_Length_tep = File_Length;
                Int32 RM6935x_Demura_part2_addr = 0x300000; //第3笔补偿数据起始地址
                Int32 RM6935x_Demura_part2_length = 0xC886 + 0x09;//第3笔补偿数据总长，256取整
                File_Length_tep = RM6935x_Demura_part2_length;
                File_Length = RM6935x_Demura_part2_length;
                while (tx_en)
                {
                    if (File_Length_tep > (File_Length % div))
                    {
                        Once_txlen = div;
                    }
                    else  //最后一笔
                    {
                        Once_txlen = Convert.ToInt32(File_Length % div);
                        tx_en = false;
                    }
                    aFile.Seek(RM6935x_Demura_part2_addr + m_txlen, SeekOrigin.Begin);    //跳转
                    ByteReaded = aFile.Read(TemFileContent, 9, Once_txlen); // 存入第9位
                    try
                    {
                        //TemFileContent[0] = 0x5B;
                        //TemFileContent[1] = Convert.ToByte(File_Length >> 24);
                        //TemFileContent[2] = Convert.ToByte((File_Length >> 16) & 0xff);
                        //TemFileContent[3] = Convert.ToByte((File_Length >> 8) & 0xff);
                        //TemFileContent[4] = Convert.ToByte(File_Length & 0xff);
                        //MainForm.comPort.Write(TemFileContent, 0, Once_txlen + 5);
                        TemFileContent[0] = 0xbd;
                        TemFileContent[1] = 0x5B;
                        TemFileContent[2] = 0xb5;
                        TemFileContent[3] = 0xd9;
                        TemFileContent[4] = 0x9d;
                        TemFileContent[5] = Convert.ToByte(File_Length >> 24);
                        TemFileContent[6] = Convert.ToByte((File_Length >> 16) & 0xff);
                        TemFileContent[7] = Convert.ToByte((File_Length >> 8) & 0xff);
                        TemFileContent[8] = Convert.ToByte(File_Length & 0xff);
                        MainForm.comPort.Write(TemFileContent, 0, Once_txlen + 9);
                    }
                    catch
                    {
                        MessageBox.Show("串口有误，请检查", "错误");
                        tx_en = false;
                        break;
                    }
                    //tx_en = false;
                    m_txlen += ByteReaded;
                    Application.DoEvents();
                    File_Length_tep = File_Length_tep - div;
                }
                aFile.Close();
            }
            catch
            {
                MessageBox.Show("请选择文件夹", "错误");
            }
        }
        private void btnPatternR_Click(object sender, EventArgs e)
        {
            // MessageBox.Show("点W");
            OLED_Show_Click(btnPatternW, e);
        }



        private void Save_VT_Gamma_Click(object sender, EventArgs e)
        {
            Save_Gamma_ViewTrix();
        }

        private void vtdr_btn_clear_Click(object sender, EventArgs e)
        {
            txtCmd5.Text = "";
        }

        private void btn_write_ram1_Click(object sender, EventArgs e)
        {
            txtCmd5.Text = "";
            //txtCmd4.Text = "IC WRITE\r\n" 
            txtCmd5.Text = "59,01\r\n"
        + "FF,FF,FF,10\r\n"
        + "11\r\n"
        + "FF,FF,FF,80\r\n"
        + "59,11\r\n";
            Send_Cmd_Click(btnSend5, e);
        }

        private void btn_write_ram2_Click(object sender, EventArgs e)
        {
            PreLoad_Demura_data_Click(btnData2DemuraRam, e);
        }

        private void btn_write_ram3_Click(object sender, EventArgs e)
        {
            txtCmd5.Text = "59,01\r\n"
        + "29\r\n";
            Send_Cmd_Click(btnSend5, e);
        }

        private void Save_Gamma_code_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.txt)|*.txt|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);

                    str = str + "0\r\n" + "1\r\n" + "3\r\n" + "5\r\n" + "7\r\n" + "11\r\n" + "15\r\n" + "19\r\n" + "23\r\n" + "27\r\n" + "31\r\n" + "35\r\n" + "39\r\n" + "47\r\n" + "55\r\n"

                    + "63\r\n" + "71\r\n" + "79\r\n" + "95\r\n" + "111\r\n" + "127\r\n" + "159\r\n" + "191\r\n" + "223\r\n" + "255\r\n";

                    //R

                    str = str + VTDR7120_R0.Value + "\r\n";
                    str = str + VTDR7120_R1.Value + "\r\n";
                    str = str + VTDR7120_R3.Value + "\r\n";
                    str = str + VTDR7120_R5.Value + "\r\n";
                    str = str + VTDR7120_R7.Value + "\r\n";
                    str = str + VTDR7120_R11.Value + "\r\n";
                    str = str + VTDR7120_R15.Value + "\r\n";
                    str = str + VTDR7120_R19.Value + "\r\n";
                    str = str + VTDR7120_R23.Value + "\r\n";
                    str = str + VTDR7120_R27.Value + "\r\n";
                    str = str + VTDR7120_R31.Value + "\r\n";
                    str = str + VTDR7120_R35.Value + "\r\n";
                    str = str + VTDR7120_R39.Value + "\r\n";
                    str = str + VTDR7120_R47.Value + "\r\n";
                    str = str + VTDR7120_R55.Value + "\r\n";
                    str = str + VTDR7120_R63.Value + "\r\n";
                    str = str + VTDR7120_R71.Value + "\r\n";
                    str = str + VTDR7120_R79.Value + "\r\n";
                    str = str + VTDR7120_R95.Value + "\r\n";
                    str = str + VTDR7120_R111.Value + "\r\n";
                    str = str + VTDR7120_R127.Value + "\r\n";
                    str = str + VTDR7120_R159.Value + "\r\n";
                    str = str + VTDR7120_R191.Value + "\r\n";
                    str = str + VTDR7120_R223.Value + "\r\n";
                    str = str + VTDR7120_R255.Value + "\r\n";

                    //G
                    str = str + VTDR7120_G0.Value + "\r\n";
                    str = str + VTDR7120_G1.Value + "\r\n";
                    str = str + VTDR7120_G3.Value + "\r\n";
                    str = str + VTDR7120_G5.Value + "\r\n";
                    str = str + VTDR7120_G7.Value + "\r\n";
                    str = str + VTDR7120_G11.Value + "\r\n";
                    str = str + VTDR7120_G15.Value + "\r\n";
                    str = str + VTDR7120_G19.Value + "\r\n";
                    str = str + VTDR7120_G23.Value + "\r\n";
                    str = str + VTDR7120_G27.Value + "\r\n";
                    str = str + VTDR7120_G31.Value + "\r\n";
                    str = str + VTDR7120_G35.Value + "\r\n";
                    str = str + VTDR7120_G39.Value + "\r\n";
                    str = str + VTDR7120_G47.Value + "\r\n";
                    str = str + VTDR7120_G55.Value + "\r\n";
                    str = str + VTDR7120_G63.Value + "\r\n";
                    str = str + VTDR7120_G71.Value + "\r\n";
                    str = str + VTDR7120_G79.Value + "\r\n";
                    str = str + VTDR7120_G95.Value + "\r\n";
                    str = str + VTDR7120_G111.Value + "\r\n";
                    str = str + VTDR7120_G127.Value + "\r\n";
                    str = str + VTDR7120_G159.Value + "\r\n";
                    str = str + VTDR7120_G191.Value + "\r\n";
                    str = str + VTDR7120_G223.Value + "\r\n";
                    str = str + VTDR7120_G255.Value + "\r\n";

                    //B
                    str = str + VTDR7120_B0.Value + "\r\n";
                    str = str + VTDR7120_B1.Value + "\r\n";
                    str = str + VTDR7120_B3.Value + "\r\n";
                    str = str + VTDR7120_B5.Value + "\r\n";
                    str = str + VTDR7120_B7.Value + "\r\n";
                    str = str + VTDR7120_B11.Value + "\r\n";
                    str = str + VTDR7120_B15.Value + "\r\n";
                    str = str + VTDR7120_B19.Value + "\r\n";
                    str = str + VTDR7120_B23.Value + "\r\n";
                    str = str + VTDR7120_B27.Value + "\r\n";
                    str = str + VTDR7120_B31.Value + "\r\n";
                    str = str + VTDR7120_B35.Value + "\r\n";
                    str = str + VTDR7120_B39.Value + "\r\n";
                    str = str + VTDR7120_B47.Value + "\r\n";
                    str = str + VTDR7120_B55.Value + "\r\n";
                    str = str + VTDR7120_B63.Value + "\r\n";
                    str = str + VTDR7120_B71.Value + "\r\n";
                    str = str + VTDR7120_B79.Value + "\r\n";
                    str = str + VTDR7120_B95.Value + "\r\n";
                    str = str + VTDR7120_B111.Value + "\r\n";
                    str = str + VTDR7120_B127.Value + "\r\n";
                    str = str + VTDR7120_B159.Value + "\r\n";
                    str = str + VTDR7120_B191.Value + "\r\n";
                    str = str + VTDR7120_B223.Value + "\r\n";
                    str = str + VTDR7120_B255.Value + "\r\n";

                    sw.WriteLine(str);
                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        }

        private void VTDR7120_B7_ValueChanged(object sender, EventArgs e)
        {

        }






        //private void PreLoad_Demura_data_Click(object sender, EventArgs e)
        //{

        //}

        private void Save_Gamma_ViewTrix()
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"txt文件(*.txt)|*.txt|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "保存VT Driver IC Gamma Code文件";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                StreamWriter sw = null; //文件流
                sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);

                int[] Rcode = new int[25] {Convert.ToInt32(VTDR7120_R0.Text, 16),Convert.ToInt32(VTDR7120_R1.Text, 16),Convert.ToInt32(VTDR7120_R3.Text, 16),Convert.ToInt32(VTDR7120_R5.Text, 16),
                                                            Convert.ToInt32(VTDR7120_R7.Text, 16),Convert.ToInt32(VTDR7120_R11.Text, 16),Convert.ToInt32(VTDR7120_R15.Text, 16),Convert.ToInt32(VTDR7120_R19.Text, 16),
                                                            Convert.ToInt32(VTDR7120_R23.Text, 16), Convert.ToInt32(VTDR7120_R27.Text, 16),Convert.ToInt32(VTDR7120_R31.Text, 16) ,Convert.ToInt32(VTDR7120_R35.Text, 16),
                                                            Convert.ToInt32(VTDR7120_R39.Text, 16),Convert.ToInt32(VTDR7120_R47.Text, 16) , Convert.ToInt32(VTDR7120_R55.Text, 16),Convert.ToInt32(VTDR7120_R63.Text, 16),
                                                            Convert.ToInt32(VTDR7120_R71.Text, 16) , Convert.ToInt32(VTDR7120_R79.Text, 16),Convert.ToInt32(VTDR7120_R95.Text, 16),Convert.ToInt32(VTDR7120_R111.Text, 16) ,
                                                            Convert.ToInt32(VTDR7120_R127.Text, 16),Convert.ToInt32(VTDR7120_R159.Text, 16),Convert.ToInt32(VTDR7120_R191.Text, 16) , Convert.ToInt32(VTDR7120_R223.Text, 16),
                                                            Convert.ToInt32(VTDR7120_R255.Text, 16) };

                int[] Gcode = new int[25] {Convert.ToInt32(VTDR7120_G0.Text, 16),Convert.ToInt32(VTDR7120_G1.Text, 16),Convert.ToInt32(VTDR7120_G3.Text, 16),Convert.ToInt32(VTDR7120_G5.Text, 16),
                                                            Convert.ToInt32(VTDR7120_G7.Text, 16),Convert.ToInt32(VTDR7120_G11.Text, 16),Convert.ToInt32(VTDR7120_G15.Text, 16),Convert.ToInt32(VTDR7120_G19.Text, 16),
                                                            Convert.ToInt32(VTDR7120_G23.Text, 16), Convert.ToInt32(VTDR7120_G27.Text, 16),Convert.ToInt32(VTDR7120_G31.Text, 16) ,Convert.ToInt32(VTDR7120_G35.Text, 16),
                                                            Convert.ToInt32(VTDR7120_G39.Text, 16),Convert.ToInt32(VTDR7120_G47.Text, 16) , Convert.ToInt32(VTDR7120_G55.Text, 16),Convert.ToInt32(VTDR7120_G63.Text, 16),
                                                            Convert.ToInt32(VTDR7120_G71.Text, 16) , Convert.ToInt32(VTDR7120_G79.Text, 16),Convert.ToInt32(VTDR7120_G95.Text, 16),Convert.ToInt32(VTDR7120_G111.Text, 16) ,
                                                            Convert.ToInt32(VTDR7120_G127.Text, 16),Convert.ToInt32(VTDR7120_G159.Text, 16),Convert.ToInt32(VTDR7120_G191.Text, 16) , Convert.ToInt32(VTDR7120_G223.Text, 16),
                                                            Convert.ToInt32(VTDR7120_G255.Text, 16) };

                int[] Bcode = new int[25] {Convert.ToInt32(VTDR7120_B0.Text, 16),Convert.ToInt32(VTDR7120_B1.Text, 16),Convert.ToInt32(VTDR7120_B3.Text, 16),Convert.ToInt32(VTDR7120_B5.Text, 16),
                                                            Convert.ToInt32(VTDR7120_B7.Text, 16),Convert.ToInt32(VTDR7120_B11.Text, 16),Convert.ToInt32(VTDR7120_B15.Text, 16),Convert.ToInt32(VTDR7120_B19.Text, 16),
                                                            Convert.ToInt32(VTDR7120_B23.Text, 16), Convert.ToInt32(VTDR7120_B27.Text, 16),Convert.ToInt32(VTDR7120_B31.Text, 16) ,Convert.ToInt32(VTDR7120_B35.Text, 16),
                                                            Convert.ToInt32(VTDR7120_B39.Text, 16),Convert.ToInt32(VTDR7120_B47.Text, 16) , Convert.ToInt32(VTDR7120_B55.Text, 16),Convert.ToInt32(VTDR7120_B63.Text, 16),
                                                            Convert.ToInt32(VTDR7120_B71.Text, 16) , Convert.ToInt32(VTDR7120_B79.Text, 16),Convert.ToInt32(VTDR7120_B95.Text, 16),Convert.ToInt32(VTDR7120_B111.Text, 16) ,
                                                            Convert.ToInt32(VTDR7120_B127.Text, 16),Convert.ToInt32(VTDR7120_B159.Text, 16),Convert.ToInt32(VTDR7120_B191.Text, 16) , Convert.ToInt32(VTDR7120_B223.Text, 16),
                                                            Convert.ToInt32(VTDR7120_B255.Text, 16) };

                //后续在此处修改
                int i = 0;
                if (VTDR7120_Gamma_Group.Value == 0)
                {
                    i = 0;
                }
                if (VTDR7120_Gamma_Group.Value == 1)
                {
                    i = 1;
                }
                if (VTDR7120_Gamma_Group.Value == 2)
                {
                    i = 2;

                }
                if (VTDR7120_Gamma_Group.Value == 3)
                {
                    i = 3;
                }
                if (VTDR7120_Gamma_Group.Value == 4)
                {
                    i = 4;
                }

                str = "BF," + i.ToString("X2");
                sw.WriteLine(str);

                // printf Gamma R
                str = "B0,";
                for (int j = 0; j < 8; j++)
                {
                    str = str + ((Rcode[j] & 0x300) >> 8).ToString("X2") + "," + (Rcode[j] & 0xFF).ToString("X2") + ",";
                }
                int leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "B1,";
                for (int j = 8; j < 16; j++)
                {
                    str = str + ((Rcode[j] & 0x300) >> 8).ToString("X2") + "," + (Rcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "B2,";
                for (int j = 16; j < 24; j++)
                {
                    str = str + ((Rcode[j] & 0x300) >> 8).ToString("X2") + "," + (Rcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "B3," + ((Rcode[24] & 0x300) >> 8).ToString("X2") + "," + (Rcode[24] & 0xFF).ToString("X2");
                sw.WriteLine(str);


                //printf Gamma G
                str = "B4,";
                for (int j = 0; j < 8; j++)
                {
                    str = str + ((Gcode[j] & 0x300) >> 8).ToString("X2") + "," + (Gcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "B5,";
                for (int j = 8; j < 16; j++)
                {
                    str = str + ((Gcode[j] & 0x300) >> 8).ToString("X2") + "," + (Gcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "B6,";
                for (int j = 16; j < 24; j++)
                {
                    str = str + ((Gcode[j] & 0x300) >> 8).ToString("X2") + "," + (Gcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "B7," + ((Gcode[24] & 0x300) >> 8).ToString("X2") + "," + (Gcode[24] & 0xFF).ToString("X2");
                sw.WriteLine(str);


                //printf Gamma B

                str = "B8,";
                for (int j = 0; j < 8; j++)
                {
                    str = str + ((Bcode[j] & 0x300) >> 8).ToString("X2") + "," + (Bcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "B9,";
                for (int j = 8; j < 16; j++)
                {
                    str = str + ((Bcode[j] & 0x300) >> 8).ToString("X2") + "," + (Bcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "BA,";
                for (int j = 16; j < 24; j++)
                {
                    str = str + ((Bcode[j] & 0x300) >> 8).ToString("X2") + "," + (Bcode[j] & 0xFF).ToString("X2") + ",";
                }
                leng = str.Length;
                str = str.Substring(0, leng - 1);
                sw.WriteLine(str);

                str = "BB," + ((Bcode[24] & 0x300) >> 8).ToString("X2") + "," + (Bcode[24] & 0xFF).ToString("X2");
                sw.WriteLine(str);

                sw.Dispose(); //释放资源
                sw.Close(); //关闭数据流
                MessageBox.Show("Gamma保存OK！", "系统提示：");

            }
        }

        //gamma的OTP的固定部分代码
        private void btn_OTP_Gamma_Click(object sender, EventArgs e)
        {
            txtCmd4.Text = "";
            //txtCmd4.Text = "IC WRITE\r\n" 
            txtCmd4.Text = "BE,00\r\n"
        + "F0,AA,11\r\n"
        + "C8,07" + "//烧录4组GAMMA\r\n"
        + "11\r\n"
        + "FF,FF,FF,64\r\n"  //"DELAY100\r\n"
        + "28\r\n"
        + "FF,FF,FF,0A\r\n"   // "DELAY10\r\n"
        + "F0,AA,12\r\n"
        + "CA,01\r\n"
        + "FF,FF,FF,0A\r\n" // "DELAY10\r\n"
        + "E6,00,00,80\r\n"
        + "FF,FF,FF,0A\r\n" // "DELAY10\r\n"
        + "CA,03\r\n"
        + "FF,FF,FF,0A\r\n"  // "DELAY10\r\n"
        + "E7,88,55,11\r\n"
        + "FF,FF,FF,FF\r\n"
        + "FF,FF,FF,FF\r\n"  //"DELAY500\r\n"
        + "CA,01\r\n"
        + "E6,00,00,00\r\n"
        + "FF,FF,FF,0A\r\n"   //"DELAY10\r\n"
        + "CA,40\r\n"
        + "FF,FF,FF,0A\r\n"   //  "DELAY10\r\n"
        + "01\r\n";
        }
        //private void Save_Gamma_ViewTrix()
        //{

        //    SaveFileDialog sf = new SaveFileDialog(); //对话框
        //    sf.Filter = @"txt文件(*.txt)|*.txt|所有文件(*.*)|*.*"; //定义保存的文件的类型
        //    string str = "保存VT Driver IC Gamma Code文件";
        //    if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
        //    {
        //        if (sf.FileName == "") return; //如果没有输入文件名
        //        StreamWriter sw = null; //文件流
        //        sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);

        //        int[] Rcode = new int[25] {Convert.ToInt32(VTDR7120_R0.Text, 16),Convert.ToInt32(VTDR7120_R1.Text, 16),Convert.ToInt32(VTDR7120_R3.Text, 16),Convert.ToInt32(VTDR7120_R5.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_R7.Text, 16),Convert.ToInt32(VTDR7120_R11.Text, 16),Convert.ToInt32(VTDR7120_R15.Text, 16),Convert.ToInt32(VTDR7120_R19.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_R23.Text, 16), Convert.ToInt32(VTDR7120_R27.Text, 16),Convert.ToInt32(VTDR7120_R31.Text, 16) ,Convert.ToInt32(VTDR7120_R35.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_R39.Text, 16),Convert.ToInt32(VTDR7120_R47.Text, 16) , Convert.ToInt32(VTDR7120_R55.Text, 16),Convert.ToInt32(VTDR7120_R63.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_R71.Text, 16) , Convert.ToInt32(VTDR7120_R79.Text, 16),Convert.ToInt32(VTDR7120_R95.Text, 16),Convert.ToInt32(VTDR7120_R111.Text, 16) ,
        //                                                    Convert.ToInt32(VTDR7120_R127.Text, 16),Convert.ToInt32(VTDR7120_R159.Text, 16),Convert.ToInt32(VTDR7120_R191.Text, 16) , Convert.ToInt32(VTDR7120_R223.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_R255.Text, 16) };

        //        int[] Gcode = new int[25] {Convert.ToInt32(VTDR7120_G0.Text, 16),Convert.ToInt32(VTDR7120_G1.Text, 16),Convert.ToInt32(VTDR7120_G3.Text, 16),Convert.ToInt32(VTDR7120_G5.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_G7.Text, 16),Convert.ToInt32(VTDR7120_G11.Text, 16),Convert.ToInt32(VTDR7120_G15.Text, 16),Convert.ToInt32(VTDR7120_G19.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_G23.Text, 16), Convert.ToInt32(VTDR7120_G27.Text, 16),Convert.ToInt32(VTDR7120_G31.Text, 16) ,Convert.ToInt32(VTDR7120_G35.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_G39.Text, 16),Convert.ToInt32(VTDR7120_G47.Text, 16) , Convert.ToInt32(VTDR7120_G55.Text, 16),Convert.ToInt32(VTDR7120_G63.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_G71.Text, 16) , Convert.ToInt32(VTDR7120_G79.Text, 16),Convert.ToInt32(VTDR7120_G95.Text, 16),Convert.ToInt32(VTDR7120_G111.Text, 16) ,
        //                                                    Convert.ToInt32(VTDR7120_G127.Text, 16),Convert.ToInt32(VTDR7120_G159.Text, 16),Convert.ToInt32(VTDR7120_G191.Text, 16) , Convert.ToInt32(VTDR7120_G223.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_G255.Text, 16) };

        //        int[] Bcode = new int[25] {Convert.ToInt32(VTDR7120_B0.Text, 16),Convert.ToInt32(VTDR7120_B1.Text, 16),Convert.ToInt32(VTDR7120_B3.Text, 16),Convert.ToInt32(VTDR7120_B5.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_B7.Text, 16),Convert.ToInt32(VTDR7120_B11.Text, 16),Convert.ToInt32(VTDR7120_B15.Text, 16),Convert.ToInt32(VTDR7120_B19.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_B23.Text, 16), Convert.ToInt32(VTDR7120_B27.Text, 16),Convert.ToInt32(VTDR7120_B31.Text, 16) ,Convert.ToInt32(VTDR7120_B35.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_B39.Text, 16),Convert.ToInt32(VTDR7120_B47.Text, 16) , Convert.ToInt32(VTDR7120_B55.Text, 16),Convert.ToInt32(VTDR7120_B63.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_B71.Text, 16) , Convert.ToInt32(VTDR7120_B79.Text, 16),Convert.ToInt32(VTDR7120_B95.Text, 16),Convert.ToInt32(VTDR7120_B111.Text, 16) ,
        //                                                    Convert.ToInt32(VTDR7120_B127.Text, 16),Convert.ToInt32(VTDR7120_B159.Text, 16),Convert.ToInt32(VTDR7120_B191.Text, 16) , Convert.ToInt32(VTDR7120_B223.Text, 16),
        //                                                    Convert.ToInt32(VTDR7120_B255.Text, 16) };

        //        int[,] GMA_CodeR = new int[9, 25];
        //        int[,] GMA_CodeG = new int[9, 25];
        //        int[,] GMA_CodeB = new int[9, 25];

        //        int gmanumber = 0;



        //        for (int i = 0; i <= 7; i++)
        //        {
        //            if ((i > gmanumber) && (i != 7))
        //                continue;



        //            str = "BF," + i.ToString("X2");
        //            sw.WriteLine(str);

        //            //printf Gamma R
        //            str = "B0,";
        //            for (int j = 0; j < 8; j++)
        //            {
        //                str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            int leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "B1,";
        //            for (int j = 8; j < 16; j++)
        //            {
        //                str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "B2,";
        //            for (int j = 16; j < 24; j++)
        //            {
        //                str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "B3," + ((GMA_CodeR[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, 24] & 0xFF).ToString("X2");
        //            sw.WriteLine(str);

        //            //printf Gamma G
        //            str = "B4,";
        //            for (int j = 0; j < 8; j++)
        //            {
        //                str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "B5,";
        //            for (int j = 8; j < 16; j++)
        //            {
        //                str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "B6,";
        //            for (int j = 16; j < 24; j++)
        //            {
        //                str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "B7," + ((GMA_CodeG[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, 24] & 0xFF).ToString("X2");
        //            sw.WriteLine(str);

        //            //printf Gamma B
        //            str = "B8,";
        //            for (int j = 0; j < 8; j++)
        //            {
        //                str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "B9,";
        //            for (int j = 8; j < 16; j++)
        //            {
        //                str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "BA,";
        //            for (int j = 16; j < 24; j++)
        //            {
        //                str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
        //            }
        //            leng = str.Length;
        //            str = str.Substring(0, leng - 1);
        //            sw.WriteLine(str);

        //            str = "BB," + ((GMA_CodeB[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, 24] & 0xFF).ToString("X2");
        //            sw.WriteLine(str);



        //        }


        //        sw.WriteLine(str);

        //        sw.Dispose(); //释放资源
        //        sw.Close(); //关闭数据流
        //        MessageBox.Show("Gamma保存OK！", "系统提示：");

        //    }

        //}





        //private void mtSaveGamma_Click(object sender, EventArgs e)
        //{
        //    SaveFileDialog sf = new SaveFileDialog(); //对话框
        //    sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
        //    string str = "保存Gamma文件";
        //    if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
        //    {
        //        if (sf.FileName == "") return; //如果没有输入文件名
        //        try
        //        {
        //            StreamWriter sw = null; //文件流
        //            sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);

        //            str = str + "R0," + VTDR7120_R0.Text + "," + "G0," + VTDR7120_G0.Text + "," + "B0," + VTDR7120_B0.Text + "\r\n";
        //            str = str + "R1," + VTDR7120_R1.Text + "," + "G1," + VTDR7120_G1.Text + "," + "B1," + VTDR7120_B1.Text + "\r\n";
        //            str = str + "R3," + VTDR7120_R3.Text + "," + "G3," + VTDR7120_G3.Text + "," + "B3," + VTDR7120_B3.Text + "\r\n";
        //            str = str + "R5," + VTDR7120_R5.Text + "," + "G5," + VTDR7120_G5.Text + "," + "B5," + VTDR7120_B5.Text + "\r\n";
        //            str = str + "R7," + VTDR7120_R7.Text + "," + "G7," + VTDR7120_G7.Text + "," + "B7," + VTDR7120_B7.Text + "\r\n";
        //            str = str + "R11," + VTDR7120_R11.Text + "," + "G11," + VTDR7120_G11.Text + "," + "B11," + VTDR7120_B11.Text + "\r\n";
        //            str = str + "R15," + VTDR7120_R15.Text + "," + "G15," + VTDR7120_G15.Text + "," + "B15," + VTDR7120_B15.Text + "\r\n";
        //            str = str + "R19," + VTDR7120_R19.Text + "," + "G19," + VTDR7120_G19.Text + "," + "B20," + VTDR7120_B19.Text + "\r\n";
        //            str = str + "R23," + VTDR7120_R23.Text + "," + "G23," + VTDR7120_G23.Text + "," + "B23," + VTDR7120_B23.Text + "\r\n";
        //            str = str + "R27," + VTDR7120_R27.Text + "," + "G27," + VTDR7120_G27.Text + "," + "B27," + VTDR7120_B27.Text + "\r\n";
        //            str = str + "R31," + VTDR7120_R31.Text + "," + "G31," + VTDR7120_G31.Text + "," + "B31," + VTDR7120_B31.Text + "\r\n";
        //            str = str + "R35," + VTDR7120_R35.Text + "," + "G35," + VTDR7120_G35.Text + "," + "B35," + VTDR7120_B35.Text + "\r\n";
        //            str = str + "R39," + VTDR7120_R39.Text + "," + "G39," + VTDR7120_G39.Text + "," + "B39," + VTDR7120_B39.Text + "\r\n";
        //            str = str + "R47," + VTDR7120_R47.Text + "," + "G47," + VTDR7120_G47.Text + "," + "B47," + VTDR7120_B47.Text + "\r\n";
        //            str = str + "R55," + VTDR7120_R55.Text + "," + "G55," + VTDR7120_G55.Text + "," + "B55," + VTDR7120_B55.Text + "\r\n";
        //            str = str + "R63," + VTDR7120_R63.Text + "," + "G63," + VTDR7120_G63.Text + "," + "B63," + VTDR7120_B63.Text + "\r\n";
        //            str = str + "R71," + VTDR7120_R71.Text + "," + "G71," + VTDR7120_G71.Text + "," + "B71," + VTDR7120_B71.Text + "\r\n";
        //            str = str + "R79," + VTDR7120_R79.Text + "," + "G79," + VTDR7120_G79.Text + "," + "B79," + VTDR7120_B79.Text + "\r\n";
        //            str = str + "R95," + VTDR7120_R95.Text + "," + "G95," + VTDR7120_G95.Text + "," + "B95," + VTDR7120_B95.Text + "\r\n";
        //            str = str + "R111," + VTDR7120_R111.Text + "," + "G111," + VTDR7120_G111.Text + "," + "B111," + VTDR7120_B111.Text + "\r\n";
        //            str = str + "R127," + VTDR7120_R127.Text + "," + "G127," + VTDR7120_G127.Text + "," + "B127," + VTDR7120_B127.Text + "\r\n";
        //            str = str + "R159," + VTDR7120_R159.Text + "," + "G159," + VTDR7120_G159.Text + "," + "B159," + VTDR7120_B159.Text + "\r\n";
        //            str = str + "R191," + VTDR7120_R191.Text + "," + "G191," + VTDR7120_G191.Text + "," + "B191," + VTDR7120_B191.Text + "\r\n";
        //            str = str + "R223," + VTDR7120_R223.Text + "," + "G223," + VTDR7120_G223.Text + "," + "B223," + VTDR7120_B223.Text + "\r\n";
        //            str = str + "R255," + VTDR7120_R255.Text + "," + "G255," + VTDR7120_G255.Text + "," + "B255," + VTDR7120_B255.Text + "\r\n";
        //            sw.WriteLine(str);

        //            sw.Dispose(); //释放资源
        //            sw.Close(); //关闭数据流
        //            MessageBox.Show("Gamma保存OK！", "系统提示：");
        //        }
        //        catch
        //        {
        //            MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
        //        }
        //    }
        //}


        //送图的按钮
        private void OLED_Show_Vesa_Pic_Click(object sender, EventArgs e)
        {
            if (Vesa_Check.Checked == true)
            {
                Button btnTmp = (Button)sender;

                switch (btnTmp.Name)
                {

                    case "btnPattern16":
                        {
                            VTDR7120_btnPrevPic_Run("P16" + ".dsc_0001.bmp");
                        }
                        break;

                    case "btnPattern32":
                        {
                            VTDR7120_btnPrevPic_Run("P32" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnPattern64":
                        {
                            VTDR7120_btnPrevPic_Run("P64" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnPattern96":
                        {
                            VTDR7120_btnPrevPic_Run("P96" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnPattern128":
                        {
                            VTDR7120_btnPrevPic_Run("P128" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnPattern192":
                        {
                            VTDR7120_btnPrevPic_Run("P192" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnPattern224":
                        {
                            VTDR7120_btnPrevPic_Run("P224" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnwhite":
                        {
                            VTDR7120_btnPrevPic_Run("A255" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnred":
                        {
                            VTDR7120_btnPrevPic_Run("R255" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btngreen":
                        {
                            VTDR7120_btnPrevPic_Run("G255" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnblue":
                        {
                            VTDR7120_btnPrevPic_Run("B255" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btnblack":
                        {
                            VTDR7120_btnPrevPic_Run("A0" + ".dsc_0001.bmp");
                        }
                        break;
                    case "btn_graychage":
                        {
                            VTDR7120_btnPrevPic_Run("garychange" + ".dsc_0001.bmp");
                        }
                        break;
                }






            }
        }








    }
}
